I wanted to learn about machine learning and I stumbled upon youtube siraj and his Udacity videos and wanted to try and pick up a few things.
His video in reference: https://www.youtube.com/watch?v=vOppzHpvTiQ&index=1&list=PL2-dafEMk2A7YdKv4XfKpfbTH5z6rEEj3
In his video, he had a txt file he imported and read, but when I tried to recreate the the txt file it couldn't be read correctly. Instead, I tried to create a pandas dataframe with the same data and perform the linear regression/predict on it, but then I got the below error.
Found input variables with inconsistent numbers of samples: [1, 16] and something about passing 1d arrays and I need to reshape them.
Then when I tried to reshape them following this post: Sklearn : ValueError: Found input variables with inconsistent numbers of samples: [1, 6]
I get this error....
shapes (1,16) and (1,1) not aligned: 16 (dim 1) != 1 (dim 0)
This is my code down below. I know it's probably a syntax error, I'm just not familiar with this scklearn yet and would like some help.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn import linear_model
#DF = pd.read_fwf('BrainBodyWeight.txt')
DF = pd.DataFrame()
DF['Brain'] = [3.385, .480, 1.350, 465.00,36.330, 27.660, 14.830, 1.040, 4.190, 0.425, 0.101, 0.920, 1.000, 0.005, 0.060, 3.500 ]
DF['Body'] = [44.500, 15.5, 8.1, 423, 119.5, 115, 98.2, 5.5,58, 6.40, 4, 5.7,6.6, .140,1, 10.8]
x = DF['Brain']
y = DF['Body']
x = x.tolist()
y = y.tolist()
x = np.asarray(x)
y = np.asarray(y)
body_reg = linear_model.LinearRegression()
except Exception as e:
Can anyone explain why sklearn doesn't like my input????