Python 我发现引用的错误显示为;此MinMaxScaler实例尚未安装。”;怎么办?

Python 我发现引用的错误显示为;此MinMaxScaler实例尚未安装。”;怎么办?,python,tensorflow,predict,epoch,Python,Tensorflow,Predict,Epoch,NotFittedError回溯(最近一次呼叫最后一次) 在里面 7返回sy.逆变换([[scaled_price]])[0][0] 8. ---->9预测(56.32,w,b) NotFitteError:此MinMaxScaler实例尚未安装。在使用此估计器之前,请使用适当的参数调用“fit”。您没有从sx调用fit您能帮助我如何调用fit吗?我搞不懂,就像你说的sy.fit\u transform,你也需要用sx做同样的事情,谢谢你。 from sklearn import preproc

NotFittedError回溯(最近一次呼叫最后一次) 在里面 7返回sy.逆变换([[scaled_price]])[0][0] 8. ---->9预测(56.32,w,b)


NotFitteError:此MinMaxScaler实例尚未安装。在使用此估计器之前,请使用适当的参数调用“fit”。

您没有从
sx
调用
fit
您能帮助我如何调用fit吗?我搞不懂,就像你说的
sy.fit\u transform
,你也需要用
sx
做同样的事情,谢谢你。
from sklearn import preprocessing
sx = preprocessing.MinMaxScaler()
sy = preprocessing.MinMaxScaler()

scaled_X = sy.fit_transform(df['rate_squarefeet'].values.reshape(df.shape[0],1))

scaled_X
scaled_y=sy.fit_transform(df['Total_room'].values.reshape(df.shape[0],1))
scaled_y
def batch_gradient_descent(X, y_true, epochs, learning_rate = 0.01):

    number_of_features = X.shape[1]
    # numpy array with 1 row and columns equal to number of features. In 
    # our case number_of_features = 2 (area, bedroom)
    w = np.ones(shape=(number_of_features)) 
    b = 0
    total_samples = X.shape[0] # number of rows in X
    
    squarefeet_list = []
    epoch_list = []
    
    for i in range(epochs):        
        y_predicted = np.dot(w, X.T) + b

        w_grad = -(2/total_samples)*(X.T.dot(y_true-y_predicted))
        b_grad = -(2/total_samples)*np.square(y_true-y_predicted)
        
        w = w - learning_rate * w_grad
        b = b - learning_rate * b_grad
        
        squarefeet = np.mean(np.transpose(y_true-y_predicted))
        
        if i%10==0:
            squarefeet_list.append(squarefeet)
            epoch_list.append(i)
        
    return w, b, squarefeet, squarefeet_list, epoch_list

w, b, squarefeet, squarefeet_list, epoch_list = batch_gradient_descent(scaled_X,scaled_y.reshape(scaled_y.shape[0],),500)
w, b, squarefeet
def predict(squarefeet,w,b):
    scaled_X = sx.transform([[squarefeet]])
    scaled_price = w[0] * scaled_X[0]+b
    return sy.inverse_transform([[scaled_price]])[0][0]

predict(56.32,w,b)