Linear Regression Flashcards
(16 cards)
What is Linear Regression?
A supervised learning algorithm used to predict a continuous value based on one or more features.
What does the equation y = mX + b represent?
It represents the line of best fit where m is the slope (coefficient) and b is the intercept.
Which library provides LinearRegression in scikit-learn?
from sklearn import linear_model
How do you create a LinearRegression model?
reg = linear_model.LinearRegression()
How do you train (fit) a linear regression model?
reg.fit(X, y)
How do you make predictions using the trained model?
reg.predict([[value]])
How do you view the slope (m) of the regression line?
reg.coef_
How do you view the intercept (b) of the regression line?
reg.intercept_
What does reg.coef_ return?
The amount the output changes for each unit increase in input (slope).
What does reg.intercept_ return?
The predicted output value when the input is zero.
How do you visualize a scatter plot of the data?
Use plt.scatter(x, y, color=’red’)
How do you read a CSV file in pandas?
pd.read_csv(‘filename.csv’)
How do you drop a column from a DataFrame?
df.drop(‘column_name’, axis=1)
What kind of output does Linear Regression predict?
A continuous (numeric) value.
Why do we use Linear Regression?
To model relationships between variables and predict numerical outcomes.