import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
dataset = pd.read_csv('C:/Users/Dell/Desktop/Salary.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 1].values
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=1/3,
random_state=0)
from sklearn.linear_model import LinearRegression
simplelinearRegresson = LinearRegression()
simplelinearRegresson.fit(X_train, y_train)
y_predict = simplelinearRegresson.predict(X_test)
下面一行有错误:
y_predict_val = simplelinearRegresson.predict(11)
答案 0 :(得分:0)
您需要将标量转换为形状为(number of samples, number of features)
的2D数组。
y_predict_val = simplelinearRegresson.predict([[11]])
这是predict
方法所期望的。有关更多信息,请参见docs。