ML | sklearn.linear_model.LinearRegression() in Python Last Updated : 21 Mar, 2024 Comments Improve Suggest changes 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 mohit gupta_omg :) Follow Improve Article Tags : Machine Learning Python-Library python Practice Tags : Machine Learningpython Similar Reads Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio 10 min read Machine Learning Tutorial Machine learning is a branch of Artificial Intelligence that focuses on developing models and algorithms that let computers learn from data without being explicitly programmed for every task. In simple words, ML teaches the systems to think and understand like humans by learning from the data.It can 5 min read Linear Regression in Machine learning Linear regression is a type of supervised machine-learning algorithm that learns from the labelled datasets and maps the data points with most optimized linear functions which can be used for prediction on new datasets. It assumes that there is a linear relationship between the input and output, mea 15+ min read Support Vector Machine (SVM) Algorithm Support Vector Machine (SVM) is a supervised machine learning algorithm used for classification and regression tasks. It tries to find the best boundary known as hyperplane that separates different classes in the data. It is useful when you want to do binary classification like spam vs. not spam or 9 min read Logistic Regression in Machine Learning Logistic Regression is a supervised machine learning algorithm used for classification problems. Unlike linear regression which predicts continuous values it predicts the probability that an input belongs to a specific class. It is used for binary classification where the output can be one of two po 11 min read K means Clustering â Introduction K-Means Clustering is an Unsupervised Machine Learning algorithm which groups unlabeled dataset into different clusters. It is used to organize data into groups based on their similarity. Understanding K-means ClusteringFor example online store uses K-Means to group customers based on purchase frequ 4 min read K-Nearest Neighbor(KNN) Algorithm K-Nearest Neighbors (KNN) is a supervised machine learning algorithm generally used for classification but can also be used for regression tasks. It works by finding the "k" closest data points (neighbors) to a given input and makesa predictions based on the majority class (for classification) or th 8 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read 100+ Machine Learning Projects with Source Code [2025] This article provides over 100 Machine Learning projects and ideas to provide hands-on experience for both beginners and professionals. Whether you're a student enhancing your resume or a professional advancing your career these projects offer practical insights into the world of Machine Learning an 5 min read Introduction to Convolution Neural Network Convolutional Neural Network (CNN) is an advanced version of artificial neural networks (ANNs), primarily designed to extract features from grid-like matrix datasets. This is particularly useful for visual datasets such as images or videos, where data patterns play a crucial role. CNNs are widely us 8 min read Like