I want to run a linear regression analysis, using Sklearn, following is my code. I get an error that says "Expected 2D array, got 1D array instead"
from sklearn.linear_model import LinearRegression
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
# import data from csv file and store it into a variable
data = pd.read_csv("Advertising.csv")
x = data.iloc[:,2]
y = data.iloc[:,4]
reg = LinearRegression(x,y)
reg.fit (x,y)
Error:
ValueError: Expected 2D array, got 1D array instead:
array=[ 37.8 39.3 45.9 41.3 10.8 48.9 32.8 19.6 2.1 2.6 5.8 24.
35.1 7.6 32.9 47.7 36.6 39.6 20.5 23.9 27.7 5.1 15.9 16.9