我想根据3 个特征和1 个目标预测一个参数。这是我的输入文件(data.csv):feature.1 feature.2 feature.3 target 1 1 1 0.0625 0.5 0.5 0.5 0.125 0.25 0.25 0.25 0.25 0.125 0.125 0.125 0.5 0.0625 0.0625 0.0625 1这是我的代码:import pandas as pdfrom sklearn.model_selection import train_test_splitfrom collections import *from sklearn.linear_model import LinearRegressionfeatures = pd.read_csv('data.csv')features.head()features_name = ['feature.1' , 'feature.2' , 'feature.3']target_name = ['target']X = features[features_name]y = features[target_name]# Split the data into training and testing setsX_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.1, random_state = 42)linear_regression_model = LinearRegression()linear_regression_model.fit(X_train,y_train)#Here is where I want to predict the target value for these inputs for 3 featuresnew_data = OrderedDict([('feature.1',0.375) ,('feature.2',0.375),('feature.3',0.375) ])new_data = pd.Series(new_data).values.reshape(1,-1)ss = linear_regression_model.predict(new_data)print (ss)根据趋势,如果我将 0.375 作为所有特征的输入,我希望得到大约 0.1875 的值。但是代码预测了这一点:[[0.44203368]]这是不正确的。我不知道问题出在哪里。有人知道我该如何解决吗?
添加回答
举报
0/150
提交
取消