Skip to content

Commit

Permalink
Update load_boston in README.md (#340)
Browse files Browse the repository at this point in the history
* Update load_boston in README.md

* Remove load_boston in regression.py

* Remove load_boston in survival.py

* Add import in regression.py

* Add import in survival.py

* Add pandas in pyproject.toml

* Remove pandas from pyproject.toml

* black format

* make lint
  • Loading branch information
jyx-su authored Nov 20, 2023
1 parent f274cd3 commit f8dce61
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ Probabilistic regression example on the Boston housing dataset:
```python
from ngboost import NGBRegressor

from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error

X, Y = load_boston(True)
#Load Boston housing dataset
data_url = "http://lib.stat.cmu.edu/datasets/boston"
raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None)
X = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])
Y = raw_df.values[1::2, 2]

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)

ngb = NGBRegressor().fit(X_train, Y_train)
Expand Down
9 changes: 7 additions & 2 deletions examples/regression.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from sklearn.datasets import load_boston
import numpy as np
import pandas as pd
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split

from ngboost import NGBRegressor
from ngboost.distns import Normal

if __name__ == "__main__":
# Load Boston housing dataset
data_url = "http://lib.stat.cmu.edu/datasets/boston"
raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None)
X = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])
Y = raw_df.values[1::2, 2]

X, Y = load_boston(return_X_y=True)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)

ngb = NGBRegressor(Dist=Normal).fit(X_train, Y_train)
Expand Down
8 changes: 6 additions & 2 deletions examples/survival.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import numpy as np
from sklearn.datasets import load_boston
import pandas as pd
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split

from ngboost import NGBSurvival
from ngboost.distns import LogNormal

if __name__ == "__main__":
# Load Boston housing dataset
data_url = "http://lib.stat.cmu.edu/datasets/boston"
raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None)
X = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])
Y = raw_df.values[1::2, 2]

X, Y = load_boston(return_X_y=True)
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)

# introduce administrative censoring
Expand Down

0 comments on commit f8dce61

Please sign in to comment.