Linear Regression on Pandas DataFrame using Sklearn ( IndexError: tuple index out of range)

后端 未结 5 2220
孤街浪徒
孤街浪徒 2020-12-08 15:14

I\'m new to Python and trying to perform linear regression using sklearn on a pandas dataframe. This is what I did:

data = pd.read_csv(\'xxxx.csv\')
<         


        
5条回答
  •  广开言路
    2020-12-08 15:58

    Dataset

    Importing the libraries

    import numpy as np
    import matplotlib.pyplot as plt
    import pandas as pd
    from sklearn.linear_model import LinearRegression
    

    Importing the dataset

    dataset = pd.read_csv('1.csv')
    X = dataset[["mark1"]]
    y = dataset[["mark2"]]
    

    Fitting Simple Linear Regression to the set

    regressor = LinearRegression()
    regressor.fit(X, y)
    

    Predicting the set results

    y_pred = regressor.predict(X)
    

    Visualising the set results

    plt.scatter(X, y, color = 'red')
    plt.plot(X, regressor.predict(X), color = 'blue')
    plt.title('mark1 vs mark2')
    plt.xlabel('mark1')
    plt.ylabel('mark2')
    plt.show()
    

提交回复
热议问题