• + 1 comment
    import numpy as np
    from sklearn.linear_model import LinearRegression
    
    Physics = [  15,  12,  8,   8,   7,   7,   7,   6,   5,   3]
    History = [ 10,  25,  17,  11,  13,  17,  20,  13,  9,   15]
    
    #Sample data
    X = np.array(Physics).reshape((-1, 1))
    y = np.array(History)
    
    #Create and train the model
    model = LinearRegression()
    model.fit(X, y)
    
    #Get the slope (coefficient)
    slope = model.coef_[0]
    slope