我正在尝试使用CSV文件中的数据制作多项式回归线

时间:2019-07-03 10:58:59

标签: python pandas csv linear-regression polynomials

我的代码正在运行,但是不会给出任何输出,我不确定为什么? Here is a picture of the file phillies_of

import csv
import numpy as np
import random
import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
from sklearn import linear_model
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures

#national league east
phillies_of = pd.read_csv('/Users/hannahbeegle/Desktop/Teams/PHILLIES.csv', header = None)
phillies_pr = pd.read_csv('/Users/hannahbeegle/Desktop/Teams/PHILLIES_PR.csv',header = None)

X = phillies_of.iloc[1:33, [5, 9, 10, 13, 17, 18, 21, 23, 25]].values
Y = phillies_of.iloc[1:33,2].values

poly = PolynomialFeatures(degree = 8)
X_poly = poly.fit_transform(X)

print('Done')

poly.fit(X_poly, Y)
lin2 = LinearRegression()
lin2.fit(X_poly, Y)

print('Done 2.0')

plt.scatter(X, Y, color = 'blue', s = 10)
plt.plot(X, lin2,predict(poly.fit_transform(X)), color = 'red')
plt.show()

lin2.predict(poly.fit_transform(110.0)) 

输出: 完成

0 个答案:

没有答案