I have some prepared dataframe : Customer_Age Customer_Gender count 0 17 M 846 1 17 F 460 2 18 M 970 3 18 F 790 4 19 M 1188 ... ... ... ... 129 84 M 4 130 85 M 16 131 86 F 4 132 86 M 4 133 87 F 6
I want to create linear model and regression. This is my code:
from sklearn.linear_model import LinearRegression
select2 = df.groupby('Customer_Age')['Customer_Gender'].value_counts().rename('count').reset_index()
select2
x = select2['Customer_Age']
y = select2['count']
model = LinearRegression()
model.fit(x, y)
model = LinearRegression().fit(x, y)```
I get error:
ValueError: Expected 2D array, got 1D array instead:
array=[number]
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.
question from:https://stackoverflow.com/questions/65641358/linear-model-in-pandas