Error - "fit() missing 1 required positional argument: 'y'"

Getting error while implementing pipeline in ML

1 Like


As I am seeing the error you are passing 2 parameters at the time of calling it.
But 3 parameters are passed in the function.

1 Like

@dk89990 Run this command >> steps=[(‘standard scaler’,StandardScaler()),
('linear Regression,LinearRegression())],
if you find this helpful let me know :innocent:

You are missing brackets when defining the steps in LinearRegression

Refer this code
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression

Create the pipeline

pipeline = Pipeline([
(‘scaler’, StandardScaler()), # Step 1: Standard scaling
(‘regressor’, LinearRegression()) # Step 2: Linear regression

Fit the pipeline to your data, y_train)

Predict using the fitted pipeline

y_pred = pipeline.predict(X_test)

In the above example, X_train and y_train are the training data for the input features and target variable, respectively. X_test is the test data used for prediction.

The pipeline consists of two steps:

  1. Step 1: StandardScaler() is used to standardize the features by removing the mean and scaling to unit variance.
  2. Step 2: LinearRegression() is used as the regression algorithm.

When you call, y_train), it will sequentially apply the transformation (standard scaling) to the training data and then fit the linear regression model using the transformed data.

After fitting the pipeline, you can use it for prediction by calling pipeline.predict(X_test), which applies the same transformation to the test data and predicts the target variable using the fitted linear regression model.