-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from Techtonique/v0222
V0222
- Loading branch information
Showing
12 changed files
with
261 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import nnetsauce as ns | ||
import numpy as np | ||
from sklearn.datasets import load_diabetes, fetch_california_housing | ||
from sklearn.model_selection import train_test_split | ||
from sklearn.linear_model import Ridge | ||
from sklearn.ensemble import ExtraTreesRegressor, RandomForestRegressor | ||
from time import time | ||
|
||
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n") | ||
|
||
print(f"\n ----- fetch_california_housing ----- \n") | ||
|
||
data = fetch_california_housing() | ||
X = data.data | ||
y= data.target | ||
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .3, random_state = 213) | ||
print(f"X_train.shape(): {X_train.shape}") | ||
print(f"X_test.shape(): {X_test.shape}") | ||
|
||
regr = ns.PredictionInterval(obj=ExtraTreesRegressor(), | ||
method="splitconformal", | ||
level=95, | ||
seed=312) | ||
start = time() | ||
regr.fit(X_train, y_train) | ||
print(f"Elapsed: {time() - start}s") | ||
preds = regr.predict(X_test, return_pi=True) | ||
print(preds) | ||
print(f"coverage_rate: {np.mean((preds.lower<=y_test)*(preds.upper>=y_test))}") | ||
|
||
regr3 = ns.PredictionInterval(obj=ExtraTreesRegressor(), | ||
method="splitconformal", | ||
type_split="sequential", | ||
level=95, | ||
seed=312) | ||
start = time() | ||
regr3.fit(X_train, y_train) | ||
print(f"Elapsed: {time() - start}s") | ||
preds = regr3.predict(X_test, return_pi=True) | ||
print(preds) | ||
print(f"coverage_rate: {np.mean((preds.lower<=y_test)*(preds.upper>=y_test))}") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import os | ||
import pandas as pd | ||
import nnetsauce as ns | ||
import numpy as np | ||
from sklearn.linear_model import Ridge | ||
from sklearn.ensemble import ExtraTreesRegressor, RandomForestRegressor | ||
from time import time | ||
|
||
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n") | ||
|
||
url = "https://github.com/ritvikmath/Time-Series-Analysis/raw/master/ice_cream_vs_heater.csv" | ||
|
||
df = pd.read_csv(url) | ||
|
||
#df.set_index('date', inplace=True) | ||
df.set_index('Month', inplace=True) | ||
df.index.rename('date') | ||
|
||
print(df.shape) | ||
print(198*0.8) | ||
# df_train = df.iloc[0:97,] | ||
# df_test = df.iloc[97:123,] | ||
df_train = df.iloc[0:158,] | ||
df_test = df.iloc[158:198,] | ||
|
||
regr = ns.PredictionInterval(obj=Ridge(), | ||
method="splitconformal", | ||
type_split="sequential", | ||
level=95, | ||
seed=312) | ||
|
||
print(df_test) | ||
obj_MTS = ns.MTS(regr, lags = 25, n_hidden_features=10, verbose = 1) | ||
obj_MTS.fit(df_train) | ||
print("\n") | ||
print(obj_MTS.predict(h=10, return_pi=True)) | ||
|
||
|
||
from sklearn.base import ClassifierMixin, RegressorMixin | ||
from sklearn.utils import all_estimators | ||
|
||
removed_regressors = [ | ||
"TheilSenRegressor", | ||
"ARDRegression", | ||
"CCA", | ||
"GaussianProcessRegressor", | ||
"GradientBoostingRegressor", | ||
"HistGradientBoostingRegressor", | ||
"IsotonicRegression", | ||
"MultiOutputRegressor", | ||
"MultiTaskElasticNet", | ||
"MultiTaskElasticNetCV", | ||
"MultiTaskLasso", | ||
"MultiTaskLassoCV", | ||
"OrthogonalMatchingPursuit", | ||
"OrthogonalMatchingPursuitCV", | ||
"PLSCanonical", | ||
"PLSRegression", | ||
"RadiusNeighborsRegressor", | ||
"RegressorChain", | ||
"StackingRegressor", | ||
"VotingRegressor", | ||
] | ||
|
||
for est in all_estimators(): | ||
if ( | ||
issubclass(est[1], RegressorMixin) | ||
and (est[0] not in removed_regressors) | ||
): | ||
try: | ||
print(f"Estimator: {est[0]}") | ||
obj0 = ns.PredictionInterval(obj=est[1](), | ||
method="splitconformal", | ||
type_split="sequential", | ||
level=95, | ||
seed=312) | ||
|
||
regr = ns.MTS(obj=obj0, | ||
lags=25) | ||
regr.fit(df_train) | ||
print(regr.predict(h=10, return_pi=True)) | ||
except: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.