facebook / facebook/prophet

The last line of code is running errors.

Open
#2,455 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
20.4k
Forks
4.6k
Avg merge
19h 52m
Merged PRs (30d)
1

Description

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

dataset = pd.read_csv('50_Startups.csv')
X = dataset.iloc[:, :-1].values
Y = dataset.iloc[:, 4].values

from sklearn.preprocessing import LabelEncoder, OneHotEncoder
LabEn = LabelEncoder()
X[:, 3] = LabEn.fit_transform(X[:, 3])
from sklearn.compose import ColumnTransformer
ctrans = ColumnTransformer([("encoder", OneHotEncoder(), [3])], remainder='passthrough')
X = np.array(ctrans.fit_transform(X))
X = X[:, 1:]

from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=0)

from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, Y_train)
Y_pred = regressor.predict(X_test)

import statsmodels.regression.linear_model as sm
X = np.append(arr= np.ones((50, 1)).astype(int), values= X, axis=1)
X_opt = X[:, [0, 1, 2, 3, 4, 5]]
ols = sm.OLS(endog=Y, exog= X_opt).fit()

Contributor guide

Open the contributing guide

Research direction

Reproduce the supplied Python script, including the final sm.OLS call, and capture the exact exception and traceback. Check the shapes and contents of Y and X_opt at that point, then confirm a corrected example by rerunning the script through model fitting; the issue is resolved when the final line runs without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, numpy, pandas, python, scikit-learn
Domain
data, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.