don't worry there's normal english at the bottom
import pandas as pd
import warnings
warnings.filterwarnings("ignore")
import io
import matplotlib.pyplot as plt
import json
!wget https://jupyterlite.anaconda.cloud/b0df9a1c-3954-4c78-96e6-07ab473bea1a/files/bikeshare.csv
--2022-06-18 14:49:09-- https://jupyterlite.anaconda.cloud/b0df9a1c-3954-4c78-96e6-07ab473bea1a/files/bikeshare.csv Resolving jupyterlite.anaconda.cloud (jupyterlite.anaconda.cloud)... 99.84.160.11, 99.84.160.17, 99.84.160.36, ... Connecting to jupyterlite.anaconda.cloud (jupyterlite.anaconda.cloud)|99.84.160.11|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 34111 (33K) [text/csv] Saving to: ‘bikeshare.csv’ bikeshare.csv 100%[===================>] 33.31K --.-KB/s in 0.001s 2022-06-18 14:49:10 (57.5 MB/s) - ‘bikeshare.csv’ saved [34111/34111]
df = csv_data = pd.read_csv('bikeshare.csv')
df.head()
Date | Max Temp | Month | Holiday | Weekend | home_game | n_rides | |
---|---|---|---|---|---|---|---|
0 | 2015-05-31 | 83.0 | 5.0 | 0.0 | 1.0 | 0.0 | 469 |
1 | 2015-06-01 | 56.0 | 6.0 | 0.0 | 0.0 | 0.0 | 113 |
2 | 2015-06-02 | 63.0 | 6.0 | 0.0 | 0.0 | 0.0 | 139 |
3 | 2015-06-03 | 71.0 | 6.0 | 0.0 | 0.0 | 0.0 | 131 |
4 | 2015-06-04 | 78.0 | 6.0 | 0.0 | 0.0 | 0.0 | 207 |
df_temp_rides = df.set_index('Date')[['Max Temp', 'n_rides']]
fig, axs = plt.subplots(2, 1, figsize=(18,6))
plot_temp = axs[0]
plot_rides = axs[1]
plot_temp.set_xlabel('Day')
plot_temp.set_ylabel('Max Temperature')
plot_temp.plot(df_temp_rides['Max Temp'])
plot_rides.set_xlabel('Day')
plot_rides.set_ylabel('Number of Rides')
plot_rides.plot(df_temp_rides['n_rides'])
plt.show()
from sklearn.model_selection import GridSearchCV, train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.pipeline import make_pipeline
from sklearn.ensemble import GradientBoostingRegressor
X = pd.get_dummies(df, columns=['Month'], drop_first=True).drop(['Date', 'n_rides'], axis='columns')
y = df['n_rides']
X_train, X_valid, y_train, y_valid = train_test_split(X, y, test_size=0.2)
model = make_pipeline(MinMaxScaler(), GradientBoostingRegressor())
params = {'gradientboostingregressor__max_depth': range(3,20)}
grid = GridSearchCV(model, params, cv=5)
grid.fit(X_train, y_train)
grid.best_estimator_.score(X_valid, y_valid)
0.6314519865059818
grid.best_params_
{'gradientboostingregressor__max_depth': 3}
variances = grid.best_estimator_.named_steps['gradientboostingregressor'].feature_importances_
series = pd.Series(variances, index=X.columns, name='Explained Variances')
plt.figure(figsize=(18,6))
plt.bar(series.index,series)
plt.show()
I know what you're thinking.
omg wtf is this u hvn't posted in so long did u die and now ur writing all this ML code like a psycho
No I wasn't off in the dark just learning this kind of stuff. I just copied this notebook from somewhere. I literally have no clue what it means so we're on the same page there unless you're a ML engineer then not on the same page and good for you friend.
Lots of stuff has happened since I wrote last but I have mostly been stuck in a rut with programming. After starting a position in software support and looking at disgusting, grotesque, repulsive, foul and offensive .net code all day, sometimes I don't feel up to writing my own disgusting, grotesque, repulsive, foul, offensive code.
I sometimes feel as though problem solving has a max capacity - if you spend 8+ hours a day trying to solve problems, at the end of the day the only problems you'll feel like solving is deciding what Netflix/Amazon/SomeStreamingService+ show you're going to binge into the deep dark of a Tuesday night.
Especially a new job, where you might have zero confidence in what you're doing and everyone around you tells you "this is normal for the first two years".
Great. That's fun.
But that's just it - if you have no confidence in yourself for your job, which takes up the majority of your day then sometimes you might not even be sure if you can competently follow the directions on your ramen noodle package at the end of the day.
This is mostly to say I had a year of constant and perpetual adaptation and adjustment and all I have really learned is how much more I have to learn. Which is awesome because I love learning.
So as another debut to my own blog, here are some of the important things I've learned this year.
Time isn't real. Do what you want to do regardless if it contributes to the greater of society or not. If it makes you feel good, if it gives you confidence, if it's something that makes you feel competent, and if it's worth nothing to anyone but yourself and gets you through to tomorrow, to the end of the week, until the end of the month. Do it. (anything as long as you're not hurting anyone).
Have Values. Maybe time does matter to you and you think you're wasting the time you do have. Well then you need a set of values you can rest on so that you don't keep wasting it. Maybe there are things you don't like that you do and other things you wished you did more of. Instilling some values will give you the willpower to shrug off the 'bad' and move towards the 'good' (good and bad being relative as this is subjective to everyone).
Find your tribe. This doesn't have to look like meeting with your knitting group every day of the week that ends in y. This can be a one off thing. This year I went to Pycon after many years of telling myself I wasn't a "good enough programmer to go" or that "I wouldn't make any friends because I wasn't a good enough programmer". What actually happened: I made many friends and I was completely inspired by the people I met. I didn't understand how broadly used Python was used in every industry, from law, to biomedical sciences, to sports, to blah blah blah. It gave me the confidence that I might actually find my place as a Python user in this world.
Find a third party to unload your shit to. Maybe this makes you think of a therapist - good. That's what I meant but maybe you're uncomfortable with unloading to another human. That's fine. Find a rock to talk to. That homeless dog on your commute, or even your houseplant. As long as it's someone/something that doesn't have a stake in your life, that can hold an opinion about what you should do. If you don't learn from the stuff that's bothering you, that's called insanity. And we're all psychotic here. Don't boil in your own predispositions, your thoughts, your issues. Get that stuff out to make room for growth.
Be bored. Don't look at your phone. Don't listen to music. Don't leave the television on with no sound. Just sit down and do nothing for a bit. If you start fidgiting, if you feel uncomfortable you're doing great. Relish in this, that you can be bored. Lose yourself in it. You won't die. You might even figure out what would be more enlightenting to do than just keeping some background noise. Deep down in your utter boredom you'll find what will help you feel fulfilled or what will give you purpose.
That's it for the most part. This isn't advise. This is stuff that I have learned and I have simply transcribed it into the second person.
There will be a post coming up for Pycon, very overdue.
And to reflect on the code above - yes I copied it and I sorta kinda maybe know what it does. But for the past few months I've been struggling to feel confident and competent with programming. At the very least, I want to code something and I want it to work. I don't know who I am yet as a programmer, I don't have a style, a vein, a subject matter that I am an expert in.
There are subjects out there that I am interested in but I have zero experience in creating my own projects. So until I get an idea about what kind of thing I want to make, I'm just going to copy everyone else's stuff and see what I get from it.
Of course I won't take credit for it that would be silly but this is a practice used in many vocations (such as art, chess, martial arts, sports) to build on intutional knowledge.
This is something I have always shamed myself for - that I should be creating my own things. Well as a beginner there's so much you don't know, that you don't know that it's hard to know where to start.
And it's easy.
That's all for now, thanks for reading.