Skip to main content
. 2024 Nov 12;24(22):7223. doi: 10.3390/s24227223
Algorithm 2 Linear Regression Model Training and Prediction
  •  1:

    Load Data:

  •  2:

    df pd.read_excel(’city.xlsx’)

  •  3:

    diameterdf[diameter].values

  •  4:

    base_demanddf[base_demand].values

  •  5:

    Create Linear Regression Model:

  •  6:

    model LinearRegression()

  •  7:

    Train the Model:

  •  8:

    model.fit(diameter.reshape(1,1),base_demand)

  •  9:

    Extract Coefficients:

  • 10:

    print(modelo.coef_)

  • 11:

    Extract Intercept:

  • 12:

    print(modelo.intercept_)

  • 13:

    Generate Prediction Data:

  • 14:

    line_diameters np.linspace(min(diameter), max(diameter), 100)

  • 15:

    predictions model.predict(diameters_line.reshape(−1,1))