前提・実現したいこと
csvデータを読み込んで,その値をもとに,内挿をしたいです.
発生している問題
あるテキストにランダムな点から内挿をやる説明があったので,参照しながらプログラムを書きました.
作成したランダムな点でなく,csvデータにある点で内挿を行いたいのですが,プログラムの書き方が分かりません.以下が自作プログラムです.
python
1import matplotlib.pyplot as plt 2import seaborn as sns; sns.set() 3import numpy as np 4 5from sklearn.preprocessing import PolynomialFeatures 6x = np. array([2, 3, 4]) 7poly = PolynomialFeatures(3, include_bias=False) 8poly.fit_transform(x[:, None]) 9 10rng = np.random.RandomState(1) 11x = 10* rng.rand(50) 12y = np.sin(x)+0.1*rng.randn(50) 13 14 15from sklearn.linear_model import LinearRegression 16model = LinearRegression(fit_intercept=True) 17model.fit(x[:, np.newaxis], y) 18xfit = np.linspace(0, 10, 1000) 19 20from sklearn.pipeline import make_pipeline 21poly_model = make_pipeline(PolynomialFeatures(12),LinearRegression()) 22 23 24poly_model.fit(x[:, np.newaxis], y) 25yfit = poly_model.predict(xfit[:, np.newaxis]) 26 27plt.scatter(x,y) 28plt.plot(xfit, yfit) 29 30 31# 描画実行 32plt.show() 33
また,読み込みたいcsvデータは以下のものです.
csv
1x, z 20, 2 30.8, 9 41, 10 52, -1 63, 11 74, 0 85, 8 95.1, 8.3 105.3, 8.2 116, 3 127, 11 137.1, 10 147.2, 11 157.3, 10.5 168, -6 178.1, -3.9 188.15, -3.1 199, 9 2010, 2 2111, 10 2211.6, 10.2 2312, -1 2412.1, -1.2 2513, 5 2614, -2 2714.8, 6.7 2815, 7 2916, 0
また,内挿をおこない,得たグラフの各座標値(xを0.1間隔ぐらいで)をcsvデータとして得ることも行いたいです.
プログラムを書くことに慣れておらず,書き方がわからないため,ご教示頂けると幸いです.
よろしくお願いいたします.
補足情報(FW/ツールのバージョンなど)
python3.6を使用しています.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/17 13:10