linear-regression

How to fix this for loop problem in python?

How to fix this for loop problem in python? Question: Dataset: df = pd.read_excel(‘sales.xlsx’) x = df[‘Temperature (°C)’] y = df[‘Ice Cream Sales ($)’] df I made another table for regression squared error and used for loop to perform the y – ŷᵢ formula using this code: sse = pd.DataFrame() sse[‘Temperature (x)’] = x sse[‘Ice …

Total answers: 2

Fit the data to multivariable linear regression in Python

Fit the data to multivariable linear regression in Python Question: I have the following data: x1=[100, 100, 110, 110, 120, 120, 120, 130, 130, 130] x2=[1, 2, 1, 2, 1, 2, 3, 1, 2, 3] y=[113, 118, 127, 132, 136, 144, 138, 146, 156, 149] And I want to fit a function having the form …

Total answers: 1

Task: Finding lowest possible MSE using linear regression

Task: Finding lowest possible MSE using linear regression Question: I’ve seen this same question on here which has helped me get this far but i’m not getting the correct results. I have a linear regression with the datapoints x and y, as well as the model ypred = a*x+b. I needed to set a = …

Total answers: 2

Linear Regression with part of pandas dataframe for 300 columns

Linear Regression with part of pandas dataframe for 300 columns Question: I have a pandas dataframe with the heat production of 300 devices mapped on the outside tempearture which looks like this: Dataframe I now want to do a linear regression (y= ß0+ ß1*x1) on all 300 heatig_devices for the temperature range 2 to 3.5. …

Total answers: 2

Linear regression (Gradient descent) single feature

Linear regression (Gradient descent) single feature Question: import numpy as np import matplotlib.pyplot as plt from sklearn import linear_model class gradientdescent: def fit(self,X,Y): lr=0.01 m=5 b=0 m_gradient=0 for _ in range(1000): m_gradient= (lr*(np.sum((m*X+b-Y)*X))/(np.size(X))) b_gradient= (lr*(np.sum(m*X+b-Y))/(np.size(X))) self.m=m-m_gradient #this part is giving me conflicting results self.b=b-b_gradient #and this part def predict(self,X): return self.m*X+self.b X=np.array([1,2,3,4,5,6,7,8]) Y=np.array([1,2,4,4,5,7,8,8]) clf=gradientdescent() clf.fit(X,Y) …

Total answers: 1

why do we use fit() before predict() in LinearRegression

why do we use fit() before predict() in LinearRegression Question: Why do we use fit before giving a LinearRegression model a predict method Imean in this book I didn’t even give it a proper training dataset I mean when we give fit doesn’t it just fits the data why do we need to predict something …

Total answers: 2

Linear regression predict() error [Python]

Linear regression predict() error: UserWarning: X does not have valid feature names, but LinearRegression was fitted with feature names Question: I am trying to use my linearRegression() model to make a prediction based on a new x value. TThe x value is within the ranges of my regression model. My code is as follows: x=df[[‘A’]] …

Total answers: 1

How to find slope of LinearRegression using sklearn on python?

How to find slope of LinearRegression using sklearn on python? Question: I’m newbie in python and I would like to find slope and intercept using sklearn package. Below is my code. import numpy as np from sklearn.linear_model import LinearRegression def findLinearRegression(): x = [1,2,3,4,5] y = [5,7,12,9,15] lrm = LinearRegression() lrm.fit(x,y) m = lrm.coef_ c …

Total answers: 3