import pandas as pd
import numpy as np
import sklearn
from sklearn import linear_model
from sklearn.utils import shuffle
data = pd.read_csv("insurance.csv")
data = data[["age","children"]]
predict = "age"
x = np.array(data.drop([predict],1))
y = np.array(data[predict])
x_train , x_test , Y_train , y_test = sklearn.model_selection.train_test_split(x,y, test_size=0.1)
linear = linear_model.LinearRegression()
linear.fit(x_train , y_test)
acc = linear.score(x_test , y_test)
print(acc)
print('co: \n' ,linear.coef_)
print('intercept: \n' ,linear.intercept_)
predictions = linear.predict(x_test)
for x in range(len(predictions)):
print(predictions[x] , x_test[x] , y_test[x])
Traceback (most recent call last):
File "C:/Users/Alessandro/PycharmProjects/proggetti/machineLearning_2.py", line 17, in <module>
linear.fit(x_train , y_test)
File "C:\Users\Alessandro\anaconda3\envs\tensor\lib\site-packages\sklearn\linear_model\_base.py", line 506, in fit
y_numeric=True, multi_output=True)
File "C:\Users\Alessandro\anaconda3\envs\tensor\lib\site-packages\sklearn\base.py", line 432, in _validate_data
X, y = check_X_y(X, y, **check_params)
File "C:\Users\Alessandro\anaconda3\envs\tensor\lib\site-packages\sklearn\utils\validation.py", line 73, in inner_f
return f(**kwargs)
File "C:\Users\Alessandro\anaconda3\envs\tensor\lib\site-packages\sklearn\utils\validation.py", line 813, in check_X_y
check_consistent_length(X, y)
File "C:\Users\Alessandro\anaconda3\envs\tensor\lib\site-packages\sklearn\utils\validation.py", line 257, in check_consistent_length
" samples: %r" % [int(l) for l in lengths])
ValueError: Found input variables with inconsistent numbers of samples: [1204, 134]