This file contains hidden or 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
['/home/glemaitre/Documents/data/cycling/user_3/2015/2015-01-03-10-28-33.fit', | |
'/home/glemaitre/Documents/data/cycling/user_3/2015/2015-01-09-18-14-34.fit', | |
'/home/glemaitre/Documents/data/cycling/user_3/2015/2015-01-16-18-20-45.fit', | |
'/home/glemaitre/Documents/data/cycling/user_3/2015/2015-01-22-17-58-25.fit', | |
'/home/glemaitre/Documents/data/cycling/user_3/2015/2015-01-23-17-36-40.fit', | |
'/home/glemaitre/Documents/data/cycling/user_3/2015/2015-01-30-18-03-10.fit', | |
'/home/glemaitre/Documents/data/cycling/user_3/2015/2015-02-01-17-14-54.fit', | |
'/home/glemaitre/Documents/data/cycling/user_3/2015/2015-02-06-18-22-13.fit', | |
'/home/glemaitre/Documents/data/cycling/user_3/2015/2015-02-13-18-21-15.fit', | |
'/home/glemaitre/Documents/data/cycling/user_3/2015/2015-02-14-09-05-54.fit', |
This file contains hidden or 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
import os | |
import pandas as pd | |
import numpy as np | |
from sklearn.ensemble import make_stack_layer | |
from sklearn.preprocessing import FunctionTransformer | |
from sklearn.experimental import make_column_transformer | |
from sklearn.pipeline import make_pipeline | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.preprocessing import CategoricalEncoder |
This file contains hidden or 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
from sklearn.datasets import load_diabetes | |
from sklearn.compose import TransformedTargetRegressor | |
from sklearn.model_selection import GridSearchCV | |
from sklearn.ensemble import RandomForestRegressor | |
from sklearn.linear_model import LinearRegression | |
X, y = load_diabetes(return_X_y=True) | |
ttr = TransformedTargetRegressor() | |
grid = [{'regressor': [RandomForestRegressor()], 'regressor__n_estimators': [10, 20]}, |
This file contains hidden or 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
In [16]: df = pd.DataFrame({'A': [1, 2, 1, 2, 1, 2, 3, 3]}) | |
In [17]: df2 = df[df['A'].isin([1, 2])] | |
In [18]: df2.loc[df2['A'] == 1, 'A'] = 4 | |
/home/glemaitre/miniconda3/lib/python3.7/site-packages/pandas/core/indexing.py:189: SettingWithCopyWarning: | |
A value is trying to be set on a copy of a slice from a DataFrame | |
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy | |
self._setitem_with_indexer(indexer, value) |
This file contains hidden or 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
import asyncio | |
import random | |
import time | |
from concurrent.futures import ProcessPoolExecutor | |
def simulator_submission(): | |
"""Give ``None`` or a submission id.""" | |
return random.choice([random.randint(0, 1000), None]) |
This file contains hidden or 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
import cv2 | |
import matplotlib.pyplot as plt | |
from matplotlib.animation import FuncAnimation | |
def grab_frame(cap): | |
_, frame = cap.read() | |
return cv2.cvtColor(frame,cv2.COLOR_BGR2RGB) | |
This file contains hidden or 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
# %% | |
from sklearn.datasets import make_classification | |
from sklearn.model_selection import StratifiedShuffleSplit | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.pipeline import make_pipeline | |
from sklearn.model_selection import cross_validate | |
RANDOM_SEED = 2 |
This file contains hidden or 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
In [1]: import numpy as np | |
In [2]: X = ["One", "string"] | |
In [3]: X | |
Out[3]: ['One', 'string'] | |
In [4]: X[0] | |
Out[4]: 'One' |
This file contains hidden or 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
@pytest.mark.parametrize("name, Tree", REG_TREES.items()) | |
@pytest.mark.parametrize("criterion", REG_CRITERIONS) | |
def test_diabetes_overfit(name, Tree, criterion): | |
# check consistency of overfitted trees on the diabetes dataset | |
# since the trees will overfit, we expect an MSE of 0 | |
reg = Tree(criterion=criterion, random_state=0) | |
reg.fit(diabetes.data, diabetes.target) | |
score = mean_squared_error(diabetes.target, reg.predict(diabetes.data)) | |
assert score == pytest.approx(0), ( | |
f"Failed with {name}, criterion = {criterion} and score = {score}" |
This file contains hidden or 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
import pandas as pd | |
import pytest | |
def func(expected_columns): | |
df = pd.DataFrame({ | |
"A": [1, 2, 3], | |
"B": [1, 2, 3], | |
"C": [1, 2, 3] |