I really need your help! I've written this code:
from sklearn.model_selection import train_test_split
from sklearn import metrics
from sklearn.metrics import accuracy_score
def train_test_rmse(x,y):
X = df_new[feature_cols]
y = df_new['TOTAL CONSTRUCTION COST - EXCLUDING TAX']
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size = 0.2,random_state=123)
linreg = LinearRegression()
linreg.fit(X_train, y_train)
y_test = train_test_split(x, y, test_size = 0.2,random_state=123)
y_pred = linreg.predict(X_test)
print(accuracy_score(y_test, y_pred))
return np.sqrt(metrics.mean_squared_error(y_test, y_pred))
^ The code above runs correctly. But when I try to plot a scatter plot in the cell beneath:
import matplotlib.pyplot as plt
plt.scatter(y_test, y_pred)
plt.xlabel('Actual Y')
plt.ylabel('Predicted Y')
plt.show()
I get the error "name 'y_test' is not defined". Please let me know how to fix it. Thanks.