0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

dataset = pd.read_csv('Admission_Predict_Ver1.1.csv')
print(dataset)

x1 = dataset.drop('SOP', axis='columns')
print(x1)  

x = dataset.iloc[:,1:-1].values 
y = dataset.iloc[:,-1].values

from sklearn.model_selection import train_test_split
x_tr,x_te,y_tr,y_te = train_test_split(x,y,test_size = 0.2, random_state = 0) 

from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(x_tr,y_tr) 

y_pred = regressor.predict(x_te) 

import pickle

with open('model_pickle','wb') as f:
pickle.dump(y_pred,f) 

with open('model_pickle','rb') as f:
pickle.load(f) 

gre_score = float(input("Enter GRE Score: "))
toefl_score = float(input("Enter TOEFL Score: "))
university_rating = float(input("Enter University Rating: "))
cgpa = float(input("Enter CGPA: "))
research = float(input("Enter Research: ")) 

result = regressor.predict([gre_score,toefl_score,university_rating,cgpa,research]) 
print(result) 

我正在尝试在 Web 应用程序中部署机器学习模型之上,但在打印预测时给出了低于值的错误。我必须做些什么来解决它!

ValueError: Expected 2D array, got 1D array instead:
array=[337.   118.     4.     4.5    9.65].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or 
array.reshape(1, -1) if it contains a single sample.
4

1 回答 1

0

用这个:

x = dataset.iloc[:,1:-1].values 
y = dataset.iloc[:,-1].values

# reshaping to 1D
x = np.array(x).reshape(-1,1)
y = np.array(y).reshape(-1,1)

这会将您的数据重塑为一维数据。

于 2021-02-01T17:05:05.440 回答