ML | sklearn.linear_model.LinearRegression() in Python Last Updated : 21 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report This is Ordinary least squares Linear Regression from sklearn.linear_module. Syntax : sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1): Parameters : fit_intercept : [boolean, Default is True] Whether to calculate intercept for the model. normalize : [boolean, Default is False] Normalisation before regression. copy_X : [boolean, Default is True] If true, make a copy of X else overwritten. n_jobs : [int, Default is 1] If -1 all CPU's are used. This will speedup the working for large datasets to process. In the given dataset, R&D Spend, Administration Cost and Marketing Spend of 50 Companies are given along with the profit earned. The target is to prepare ML model which can predict the profit value of a company if the value of its R&D Spend, Administration Cost and Marketing Spend are given. . Code: Use of Linear Regression to predict the Companies Profit Python3 1== # Importing the libraries import numpy as np import pandas as pd # Importing the dataset dataset = pd.read_csv('https://media.geeksforgeeks.org/wp-content/uploads/50_Startups.csv') print ("Dataset.head() \n ", dataset.head()) # Input values x = dataset.iloc[:, :-1].values print("\nFirst 10 Input Values : \n", x[0:10, :]) Python3 1== print ("Dataset Info : \n") print (dataset.info()) Python3 1== # Input values x = dataset.iloc[:, :-1].values print("\nFirst 10 Input Values : \n", x[0:10, :]) # Output values y = dataset.iloc[:, 3].values y1 = y y1 = y1.reshape(-1, 1) print("\n\nFirst 10 Output true value : \n", y1[0:10, :]) Python3 1== # Dividing input and output data to train and test data # Training : Testing = 80 : 20 from sklearn.cross_validation import train_test_split xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size = 0.2, random_state = 0) # Feature Scaling # Multilinear regression takes care of Feature Scaling # So we need not do it manually # Fitting Multi Linear regression model to training model from sklearn.linear_model import LinearRegression regressor = LinearRegression() regressor.fit(xtrain, ytrain) # predicting the test set results y_pred = regressor.predict(xtest) y_pred1 = y_pred y_pred1 = y_pred1.reshape(-1,1) print("\n RESULT OF LINEAR REGRESSION PREDICTION : ") print ("\nFirst 10 Predicted value : \n", y_pred1[0:10, :]) Comment More infoAdvertise with us Next Article ML | sklearn.linear_model.LinearRegression() in Python M mohit gupta_omg :) Follow Improve Article Tags : Machine Learning Python-Library python Practice Tags : Machine Learningpython Similar Reads Simple Linear Regression in Python Simple linear regression models the relationship between a dependent variable and a single independent variable. In this article, we will explore simple linear regression and it's implementation in Python using libraries such as NumPy, Pandas, and scikit-learn.Understanding Simple Linear RegressionS 7 min read Solving Linear Regression in Python Linear regression is a widely used statistical method to find the relationship between dependent variable and one or more independent variables. It is used to make predictions by finding a line that best fits the data we have. The most common approach to best fit a linear regression model is least-s 3 min read Python | Linear Regression using sklearn Linear Regression is a machine learning algorithm based on supervised learning. It performs a regression task. Regression models a target prediction value based on independent variables. It is mostly used for finding out the relationship between variables and forecasting. Different regression models 3 min read Ordinary Least Squares and Ridge Regression Variance in Scikit Learn In statistical modeling, Ordinary Least Squares (OLS) and Ridge Regression are two widely used techniques for linear regression analysis. OLS is a traditional method that finds the line of best fit through the data by minimizing the sum of the squared errors between the predicted and actual values. 7 min read Save and Load Machine Learning Models in Python with scikit-learn In this article, let's learn how to save and load your machine learning model in Python with scikit-learn in this tutorial. Once we create a machine learning model, our job doesn't end there. We can save the model to use in the future. We can either use the pickle or the joblib library for this purp 4 min read Like