Почему он считает "plt" недопустимым синтаксисом? - PullRequest
0 голосов
/ 02 апреля 2020

Я подготовил модель полиномиальной регрессии, все выглядит хорошо, только что есть проблема с matplotlib! Я не знаю, что, черт возьми, не так! Но я сейчас расстроен! Вот код: #

 Data Preprocessing Template

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Position_Salaries.csv')
X = dataset.iloc[:,1:2].values
y = dataset.iloc[:, 2].values

# Splitting the dataset into the Training set and Test set
'''from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)'''

# Feature Scaling
"""from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)
sc_y = StandardScaler()
y_train = sc_y.fit_transform(y_train)"""

from sklearn.linear_model import LinearRegression
lin_reg=LinearRegression()
lin_reg.fit(X,y)

from sklearn.preprocessing import PolynomialFeatures
poly_reg=PolynomialFeatures(degree = 4)
X_poly = poly_reg.fit_transform(X)
lin_reg2=LinearRegression()
lin_reg2.fit(X_poly,y)

plt.scatter(X,y,color='Red')
plt.plot(X , lin_reg.predict(X),color='Blue')
plt.title('Truth')
plt.xlabel('Position')
plt.ylabel('Salary')
plt.show()

X_grid = np.arange(min(X),min(X), 0.1)
X_grid = np.reshape((len(X_grid),( 1))
plt.scatter( X_grid , y , color='Red') 
plt.plot(X_grid,lin_reg2.predict(poly_reg.fit_transform(X_grid)),color='Blue')
plt.title('Truth')
plt.xlabel('Position')
plt.ylabel('Salary')
plt.show()

А вот и ошибка: ---

File "<ipython-input-15-697418dc1afd>", line 3
    plt.scatter( X,y,color='Red')
      ^
SyntaxError: invalid syntax

1 Ответ

1 голос
/ 02 апреля 2020

согласно документам, reshape получает как минимум 2 параметра (вы указали только один):

numpy.reshape(a, newshape, order='C')
where:
- a : array_like
Array to be reshaped.
 - newshape : int or tuple of ints
The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One shape dimension can be -1. In this case, the value is inferred from the length of the array and remaining dimensions.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...