I try to deal with my homework. The Job is to take this Data and perform a linear regression on it.
The code is published here.
I am quite new to programming in Python and in data science. So I tried transforming as the interpreter suggests, but it didn't work. My first error was that there was a 2d array expected but 1d given. Then I took the pure array and put it into an empty one suggested by a StackOverflow answer now the error is that a scalar array is given but a 2d array is given.
import pandas as pd
from sklearn.preprocessing import StandardScaler
#Import
data = pd.read_csv('uscrime.txt', sep="\t")
crime = pd.concat([data], axis = 1)
print(crime)
from sklearn.linear_model import LinearRegression
regression = LinearRegression()
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(crime.get("M"), crime.get("Crime"), test_size=0.2, random_state=0)
X_train_new = []
X_train_new.append(X_train.values)
y_train_new = []
y_train_new.append(y_train.values)
regression.fit(X_train_new, y_train_new)