markdown stringlengths 0 37k | code stringlengths 1 33.3k | path stringlengths 8 215 | repo_name stringlengths 6 77 | license stringclasses 15
values |
|---|---|---|---|---|
Ensemble Methods
Ensemble methods use a number of models to learn on data and then average or vote among their predictions.
There are two families of ensemble methods:
- Averaging methods: Bagging methods, Random Forests, ...
- Boosting methods: AdaBoost, Gradient Tree Boosting | from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) | 04-more-supervised.ipynb | msadegh97/machine-learning-course | gpl-3.0 |
Random Forest | from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=50, min_samples_split=2)
model.fit(X_train, y_train);
model.score(X_test, y_test) | 04-more-supervised.ipynb | msadegh97/machine-learning-course | gpl-3.0 |
AdaBoost | from sklearn.ensemble import AdaBoostClassifier
model = AdaBoostClassifier(n_estimators=100)
model.fit(X_train, y_train);
model.score(X_test, y_test) | 04-more-supervised.ipynb | msadegh97/machine-learning-course | gpl-3.0 |
A repository: a group of linked commits
<!-- offline:

-->
<img src="https://raw.github.com/fperez/reprosw/master/fig/threecommits.png" >
And this is pretty much the essence of Git!
First things first: git must be configured before first use
The minimal amount of configuration for git t... | %%bash
git config --global user.name "Jeremy S. Perkins"
git config --global user.email "jeremyshane@gmail.com" | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
And how you will edit text files (it will often ask you to edit messages and other information, and thus wants to know how you like to edit your files): | %%bash
# Put here your preferred editor. If this is not set, git will honor
# the $EDITOR environment variable
git config --global core.editor /usr/bin/nano # Yes, I still use nano
# On Windows Notepad will do in a pinch, I recommend Notepad++ as a free alternative
# On the mac, you can set nano or emacs as a basic o... | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
Set git to use the credential memory cache so we don't have to retype passwords too frequently. On OSX, you should run the following (note that this requires git version 1.7.10 or newer): | %%bash
git config --global credential.helper osxkeychain
# Set the cache to timeout after 2 hours (setting is in seconds)
git config --global credential.helper 'cache --timeout=7200' | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
Github offers in its help pages instructions on how to configure the credentials helper for Linux and Windows.
Stage 1: Local, single-user, linear workflow
Simply type git to see a full list of all the 'core' commands. We'll now go through most of these via small practical exercises: | !git | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
Now let's edit our first file in the test directory with a text editor... I'm doing it programatically here for automation purposes, but you'd normally be editing by hand | %%bash
cd test
echo "My first bit of text" > file1.txt | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
Git supports aliases: new names given to command combinations. Let's make this handy shortlog an alias, so we only have to type git slog and see this compact log: | %%bash
cd test
# We create our alias (this saves it in git's permanent configuration file):
git config --global alias.slog "log --oneline --topo-order --graph"
# And now we can use it
git slog | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
And git rm works in a similar fashion.
Local user, branching
What is a branch? Simply a label for the 'current' commit in a sequence of ongoing commits:
<!-- offline:

-->
<img src="https://raw.github.com/fperez/reprosw/master/fig/masterbranch.png" >
There can be multiple branches aliv... | %%bash
cd test
git status
ls | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
We are now going to try two different routes of development: on the master branch we will add one file and on the experiment branch, which we will create, we will add a different one. We will then merge the experimental branch into master. | %%bash
cd test
git branch experiment
git checkout experiment
%%bash
cd test
echo "Some crazy idea" > experiment.txt
git add experiment.txt
git commit -a -m"Trying something new"
git slog
%%bash
cd test
git checkout master
git slog
%%bash
cd test
git status
%%bash
cd test
echo "fixed this little bug" >> file-ne... | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
Using remotes as a single user
We are now going to introduce the concept of a remote repository: a pointer to another copy of the repository that lives on a different location. This can be simply a different path on the filesystem or a server on the internet.
For this discussion, we'll be using remotes hosted on the G... | %%bash
cd test
ls
echo "Let's see if we have any remote repositories here:"
git remote -v | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
Since the above cell didn't produce any output after the git remote -v call, it means we have no remote repositories configured. We will now proceed to do so. Once logged into GitHub, go to the new repository page and make a repository called test. Do not check the box that says Initialize this repository with a REA... | %%bash
cd test
git remote add origin https://github.com/kialio/test.git
%%bash
cd test
git push -u origin master | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
We can now see this repository publicly on github.
Let's see how this can be useful for backup and syncing work between two different computers. I'll simulate a 2nd computer by working in a different directory... | %%bash
# Here I clone my 'test' repo but with a different name, test2, to simulate a 2nd computer
git clone https://github.com/kialio/test.git test2
cd test2
pwd
git remote -v | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
Now we put this new work up on the github server so it's available from the internet | %%bash
cd test2
git push | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
Now let's fetch that work from machine #1: | %%bash
cd test
git pull | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
So now let's see what happens if we try to merge the trouble branch into master: | %%bash
cd test
git merge trouble | Day_02/02_GitDevelopment/VersionControl.ipynb | saudijack/unfpyboot | mit |
<br>
Task 1: Effect of Learning Rate $\alpha$
Use Linear Regression code below using X="GrLivArea" as input variable and y="SalePrice" as target variable. Use different values of $\alpha$ given in table below and comment on why they are useful or not and which one is a good choice.
$\alpha=0.000001$:
$\alpha=0.0000000... | # Load X and y variables from pandas dataframe df_train
cols = ['GrLivArea']
X_train = np.array(df_train[cols])
y_train = np.array(df_train[["SalePrice"]])
# Get m = number of samples and n = number of features
m = X_train.shape[0]
n = X_train.shape[1]
# append a column of 1's to X for theta_0
X_train = np.insert(X_t... | assignments/.ipynb_checkpoints/assignment01-regression-checkpoint.ipynb | w4zir/ml17s | mit |
Linear Regression with Gradient Descent code | iterations = 1500
alpha = 0.000000001 # change it and find what happens
def h(X, theta): #Linear hypothesis function
hx = np.dot(X,theta)
return hx
def computeCost(theta,X,y): #Cost function
"""
theta is an n- dimensional vector, X is matrix with n- columns and m- rows
y is a matrix with m- rows ... | assignments/.ipynb_checkpoints/assignment01-regression-checkpoint.ipynb | w4zir/ml17s | mit |
Run Gradient Descent on training data | #Actually run gradient descent to get the best-fit theta values
initial_theta = np.zeros((n+1,1));
theta, theta_history, j_history = gradientDescent(X_train,y_train,initial_theta)
plt.plot(j_history)
plt.title("Convergence of Cost Function")
plt.xlabel("Iteration number")
plt.ylabel("Cost function")
plt.show() | assignments/.ipynb_checkpoints/assignment01-regression-checkpoint.ipynb | w4zir/ml17s | mit |
Plot trained line on data | # predict output for training data
hx_train= h(X_train, theta)
# plot it
plt.scatter(X_train[:,1],y_train)
plt.plot(X_train[:,1],hx_train[:,0], color='red')
plt.show() | assignments/.ipynb_checkpoints/assignment01-regression-checkpoint.ipynb | w4zir/ml17s | mit |
<br>
Task 2: Predict test data output and submit it to Kaggle
In this task we will use the model trained above to predict "SalePrice" on test data. Test data has all the input variables/features but no target variable. Out aim is to use the trained model to predict the target variable for test data. This is called gene... | # read data in pandas frame df_test and check first few rows
# write code here
df_test.head()
# check statistics of test data, make sure no data is missing.
print(df_test.shape)
df_test[cols].describe()
# Get X_test, no target variable (SalePrice) provided in test data. It is what we need to predict.
X_test = np... | assignments/.ipynb_checkpoints/assignment01-regression-checkpoint.ipynb | w4zir/ml17s | mit |
Upload .csv file to Kaggle.com
Create an account at https://www.kaggle.com
Go to https://www.kaggle.com/c/house-prices-advanced-regression-techniques/submit
Upload "predict1.csv" file created above.
Upload your score as an image below. | from IPython.display import Image
Image(filename='images/asgn_01.png', width=500) | assignments/.ipynb_checkpoints/assignment01-regression-checkpoint.ipynb | w4zir/ml17s | mit |
<br>
Task 3: Use scikit-learn for Linear Regression
In this task we are going to use Linear Regression class from scikit-learn library to train the same model. The aim is to move from understanding algorithm to using an exisiting well established library. There is a Linear Regression example available on scikit-learn w... | # import scikit-learn linear model
from sklearn import linear_model
# get X and y
# write code here
# Create linear regression object
# write code here check link above for example
# Train the model using the training sets. Use fit(X,y) command
# write code here
# The coefficients
print('Intercept: \n', reg... | assignments/.ipynb_checkpoints/assignment01-regression-checkpoint.ipynb | w4zir/ml17s | mit |
<br>
Task 4: Multivariate Linear Regression
Lastly use columns ['OverallQual', 'GrLivArea', 'GarageCars', 'TotalBsmtSF', 'YearBuilt'] and scikit-learn or the code given above to predict output on test data. Upload it to kaggle like earlier and see how much it improves your score.
Everything remains same except dimensi... | # define columns ['OverallQual', 'GrLivArea', 'GarageCars', 'TotalBsmtSF', 'YearBuilt']
# write code here
# check features range and statistics. Training dataset looks fine as all features has same count.
df_train[cols].describe()
# Load X and y variables from pandas dataframe df_train
# write code here
# Ge... | assignments/.ipynb_checkpoints/assignment01-regression-checkpoint.ipynb | w4zir/ml17s | mit |
'+ is the operator symbol, 2 and 3 are the operands
Operator Types
Arithmetic Operators
Comparison Operators
Logical Operators
Bitwise Operators
Assignment Operators
Special Operators
Arithmetic Operators | x = 15
y = 6
# Addition Operator
print('x + y = ', x + y)
# Subtraction Operator
print('x - y = ', x - y)
# Multiplication Operator
print('x * y = ', x * y)
# Division Operator
print('x / y = ', x / y) # True Division
print('x // y =', x//y) # Class Division
# Exponential Operator
print('x ** y = ', x ** y) | Python+Operators.ipynb | vravishankar/Jupyter-Books | mit |
Comparison Operators | x = 12
y = 10
# Greater Than Operator
print('x > y = ',x > y)
# Greater Than or Equal To
print('x >= y', x >= y)
# Lesser Than Operator
print('x < y = ',x < y)
# Lesser Than or Equal To
print('x <= y', x <= y)
# Equal To Operator
print('x == y ',x == y)
# Not Equal To
print('x != y', x != y) | Python+Operators.ipynb | vravishankar/Jupyter-Books | mit |
Logical Operators
<pre>
and - True if both operands are true
or - True if one of the operand is true
not - True if operand is false
</pre>
Bitwise Operators
<pre>
& -> Bitwise AND
| -> Bitwise OR
~ -> Bitwise NOT
^ -> Bitwise XOR
>> -> Bitwise Right Shift
<< -> Bitwise Left Shift
</pre> | x = 10
y = 4
# Bitwise AND
print('x & y = ', x & y)
# Bitwise OR
print('x | y = ', x | y)
# Bitwise NOT
print('~ x = ', ~ x)
# Bitwise XOR
print('x ^ y = ', x ^ y)
# Right shift
print('x >> y = ', x >> y)
# Left Shift
print('x << y = ', x << y) | Python+Operators.ipynb | vravishankar/Jupyter-Books | mit |
Assignment Operators | a = 5
print(a)
a += 5 # a = a + 5
print(a)
a -= 5 # a = a - 5
print(a)
a *= 5 # a = a * 5
print(a)
a /= 5 # a = a / 5
print(a)
a //= 2 # a = a // 2
print(a)
a %= 1 # a = a % 1
print(a)
a = 10
a **= 2 # a = a ** 2
print(a) | Python+Operators.ipynb | vravishankar/Jupyter-Books | mit |
Special Operators
Identity Operators
<pre>
is - True if the operands are identical
is not - True if the operands are not identical
</pre> | x1 = 2
y1 = 2
x2 = 'Hello'
y2 = "Hello"
x3 = [1,2,3]
y3 = (1,2,3)
print('x1 is y1 = ', x1 is y1)
print('x1 is y2 = ', x1 is y2)
print('x3 is not y3 = ', x3 is not y3) | Python+Operators.ipynb | vravishankar/Jupyter-Books | mit |
Membership Operators
<pre>
in - True if value / variable is found in sequence
not in - True if value / variable is not found in the sequence
</pre> | x = 'Hello World'
y = {1:'a',2:'b'}
print("'H' in x ", 'H' in x)
print('hello not in x ','hello' not in x)
print('1 in y = ',1 in y)
print('a in y = ',a in y) | Python+Operators.ipynb | vravishankar/Jupyter-Books | mit |
conda install numpy | ! pip install numpy -I
import numpy.core.multiarray
!pip install spacy
! pip install scipy
! pip install opencv-python
! pip install pillow
! pip install matplotlib
! pip install h5py
! pip install keras
! pip3 install https://github.com/OlafenwaMoses/ImageAI/releases/download/2.0.2/imageai-2.0.2-py... | computer-vision/computer vision.ipynb | decisionstats/pythonfordatascience | apache-2.0 |
Download the RetinaNet model file that will be used for object detection via this link
https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/resnet50_coco_best_v2.0.1.h5 | import os as os
os.getcwd()
os.chdir('C:\\Users\\KOGENTIX\\Desktop\\image')
os.getcwd()
from imageai.Detection import ObjectDetection
import os
execution_path = os.getcwd()
detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0... | computer-vision/computer vision.ipynb | decisionstats/pythonfordatascience | apache-2.0 |
What is a cross-flow turbine?
<figure style="float: right">
<img width="420px" src="figures/sandia_vawt.png">
<p class=citation>From Barone and Paquette (2012)</p>
</figure>
Axis perpendicular to flow
Little success in onshore wind
Fatigue issues
Exaggerated power ratings
<figure>
<img width="50%" src=figures/flowin... | import warnings
warnings.filterwarnings("ignore")
os.chdir(os.path.join(os.path.expanduser("~"), "Google Drive", "Research", "CFT-vectors"))
import cft_vectors
fig, ax = plt.subplots(figsize=(15, 15))
old_fontsize = plt.rcParams["font.size"]
plt.rcParams["font.size"] *= 1.5
cft_vectors.plot_diagram(fig, ax, theta_deg=... | presentation.ipynb | petebachant/2015-UNH-ME-grad-seminar-slides | mit |
Kinematics
<center>
<video width=100% controls loop>
<source src="videos/cft-animation.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</center>
<!--
embed_video("C:/Users/Pete/Google Drive/Research/CFT-vectors/videos/cft-animation.mp4")
-->
Marine hydrokinetics: ORPC
<center>
<img width... | # Generate figures from the experiments by their own methods
os.chdir("C:/Users/Pete/Research/Experiments/RVAT baseline")
import py_rvat_baseline.plotting as rvat_baseline
fig, (ax1, ax2) = plt.subplots(figsize=(14, 5), nrows=1, ncols=2)
rvat_baseline.plot_cp(ax1)
rvat_baseline.plot_cd(ax2, color=sns.color_palette()[... | presentation.ipynb | petebachant/2015-UNH-ME-grad-seminar-slides | mit |
<center>
$\lambda = \frac{\omega R}{U_\infty}$
$C_P = \frac{P_\mathrm{mech}}{\frac{1}{2}\rho A_\mathrm{f} U_\infty^3}$
$C_D = \frac{F_\mathrm{drag}}{\frac{1}{2}\rho A_\mathrm{f} U_\infty^2}$
</center>
Baseline wake measurements $(x/D=1)$
<center>
<img width=80% sr... | os.chdir(rvat_baseline_dir)
rvat_baseline.plotwake("meancontquiv", scale=1.8)
rvat_baseline.plotwake("kcont", scale=1.8) | presentation.ipynb | petebachant/2015-UNH-ME-grad-seminar-slides | mit |
Mean momentum transport
$$
\begin{split}
\frac{\partial U}{\partial x} =
\frac{1}{U} \bigg{[}
& - V\frac{\partial U}{\partial y}
- W\frac{\partial U}{\partial z} \
& -\frac{1}{\rho}\frac{\partial P}{\partial x} \
& - \frac{\partial}{\partial x} \overline{u'u'}
- \frac{\partial}{\partial y} \overline{u'v'}
- \frac{\par... | os.chdir("C:/Users/Pete/Research/Experiments/RVAT baseline")
import py_rvat_baseline.plotting as rvat_baseline
rvat_baseline.plotwake("mombargraph", scale=1.8, barcolor=None)
plt.grid(True)
os.chdir("C:/Users/Pete/Research/Experiments/RVAT baseline")
import py_rvat_baseline.plotting as rvat_baseline
rvat_baseline.pl... | presentation.ipynb | petebachant/2015-UNH-ME-grad-seminar-slides | mit |
UNH-RVAT Reynolds number dependence
Are our results relevant to full scale?
Models should be validated for the scales at which they will be applied, if possible
How cheap (small, slow) can experiments get?
$$
Re = \frac{Ul}{\nu}
$$
UNH-RVAT Reynolds number dependence | os.chdir(rvat_re_dep_dir)
import py_rvat_re_dep.plotting as rvat_re_dep
fig, (ax1, ax2) = plt.subplots(figsize=(15, 6.5), nrows=1, ncols=2)
rvat_re_dep.plot_perf_curves(ax1, ax2)
fig.tight_layout() | presentation.ipynb | petebachant/2015-UNH-ME-grad-seminar-slides | mit |
Reynolds number dependence at $\lambda = 1.9$ | os.chdir(rvat_re_dep_dir)
import py_rvat_re_dep.plotting as rvat_re_dep
fig, (ax1, ax2) = plt.subplots(figsize=(14, 6), nrows=1, ncols=2)
rvat_re_dep.plot_perf_re_dep(ax1, ax2)
fig.tight_layout() | presentation.ipynb | petebachant/2015-UNH-ME-grad-seminar-slides | mit |
Blade boundary layer dynamics
<center>
<img src="figures/McMasters-Henderson-1980.PNG" width=70%>
<p class="citation">From McMasters and Henderson (1980)</p>
</center>
Wake transport | os.chdir(rvat_re_dep_dir)
import py_rvat_re_dep.plotting as rvat_re_dep
fig, ax = plt.subplots(figsize=(13, 7))
rvat_re_dep.make_mom_bar_graph(ax, print_analysis=False)
fig.tight_layout() | presentation.ipynb | petebachant/2015-UNH-ME-grad-seminar-slides | mit |
Wake transport totals | os.chdir(rvat_re_dep_dir)
import py_rvat_re_dep.plotting as rvat_re_dep
fig, ax = plt.subplots()
rvat_re_dep.plot_wake_trans_totals(ax, emptymarkers=False, ucolor=sns.color_palette()[0],
kcolor=sns.color_palette()[1])
fig.tight_layout() | presentation.ipynb | petebachant/2015-UNH-ME-grad-seminar-slides | mit |
Numerical modeling
Experiments are expensive
Can be difficult to modify, e.g., turbine geometry
Scaling issues
Can we compute instead?
Techniques
Blade element methods: Use section characteristics to predict loading
Momentum: Very cheap, issues with high solidity, very little flow information
Vortex (potential flow)... | import warnings
warnings.filterwarnings("ignore")
os.chdir(os.path.join(os.path.expanduser("~"), "Google Drive", "Research", "CFT-vectors"))
import cft_vectors
fig, ax = plt.subplots(figsize=(15, 15))
old_fontsize = plt.rcParams["font.size"]
plt.rcParams["font.size"] *= 1.5
cft_vectors.plot_diagram(fig, ax, theta_deg=... | presentation.ipynb | petebachant/2015-UNH-ME-grad-seminar-slides | mit |
3. Dimensionality reduction
Many times we want to combine variables (for linear regression to avoid multicollinearity, to create indexes, etc)
Our data | #Read data
df_companies = pd.read_csv("data/big3_position.csv",sep="\t")
df_companies["log_revenue"] = np.log10(df_companies["Revenue"])
df_companies["log_assets"] = np.log10(df_companies["Assets"])
df_companies["log_employees"] = np.log10(df_companies["Employees"])
df_companies["log_marketcap"] = np.log10(df_companies... | class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
Correlation between variables | # Compute the correlation matrix
corr = df_companies.corr()
# Generate a mask for the upper triangle (hide the upper triangle)
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, square=True,linewidths... | class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
Revenue, employees and assets are highly correlated.
Let's imagine wwe want to explain the market capitalization in terms of the other variables. | mod = smf.ols(formula='log_marketcap ~ log_revenue + log_employees + log_assets', data=df_companies)
res = mod.fit()
print(res.summary())
#The residuals are fine
plt.figure(figsize=(4,3))
sns.regplot(res.predict(),df_companies["log_marketcap"] -res.predict())
#Get many models to see hwo coefficient changes
from stat... | class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
3.1 Combining variables
Multiplying/summing variables
It's easy
It's arbitrary | X = df_companies.loc[:,["log_revenue","log_employees","log_assets"]]
X.head(2)
#Let's scale all the columns to have mean 0 and std 1
from sklearn.preprocessing import scale
X_to_combine = scale(X)
X_to_combine
#In this case we sum them together
X_combined = np.sum(X_to_combine,axis=1)
X_combined
#Add a new column wi... | class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
3.2 PCA
Keep all the info
The resulting variables do not actually mean much | #Do the fitting
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
new_X = pca.fit_transform(X)
print("Explained variance")
print(pca.explained_variance_ratio_)
print()
print("Weight of components")
print(["log_revenue","log_employees","log_assets"])
print(pca.components_)
print()
new_X
#Create our new... | class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
3.3 Factor analysis
The observations are assumed to be caused by a linear transformation of lower dimensional latent factors and added Gaussian noise. Without loss of generality the factors are distributed according to a Gaussian with zero mean and unit covariance. The noise is also zero mean and has an arbitrary diag... | from sklearn.decomposition import FactorAnalysis
fa = FactorAnalysis(n_components=2)
new_X = fa.fit_transform(X)
print("Weight of components")
print(["log_revenue","log_employees","log_assets"])
print(fa.components_)
print()
new_X
#New variables
df_companies["fa_x1"] = new_X[:,0]
df_companies["fa_x2"] = new_X[:,1]
... | class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
Difference between FA and PCA
http://stats.stackexchange.com/questions/1576/what-are-the-differences-between-factor-analysis-and-principal-component-analysi
Principal component analysis involves extracting linear composites of observed variables.
Factor analysis is based on a formal model predicting observed variables... | Image(url="http://www.holehouse.org/mlclass/07_Regularization_files/Image.png")
from sklearn.model_selection import train_test_split
y = df_companies["log_marketcap"]
X = df_companies.loc[:,["log_revenue","log_employees","log_assets"]]
X.head(2)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33... | class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
Linear regression (to compare) | df_train = X_train.copy()
df_train["log_marketcap"] = y_train
df_train.head()
mod = smf.ols(formula='log_marketcap ~ log_revenue + log_employees + log_assets', data=df_train).fit()
print("log_revenue log_employees log_assets ")
print(mod.params.values[1:])
| class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
SVR
- Gives balanced weights (the most correlated independent variable (with the dependent) doesn't take all the weight).
- Very good when you have hundreds of variables. You can iteratively drop the worst predictor.
- It allow for more than linear "regression". The default kernel is "rbf", which fits curves. The probl... | from sklearn.svm import SVR
clf = SVR(C=0.1, epsilon=0.2,kernel="linear")
clf.fit(X_train, y_train)
print("log_revenue log_employees log_assets ")
print(clf.coef_)
| class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
Lasso
- Have a penalty
- Discards the variables with low weights. | from sklearn import linear_model
reg = linear_model.Lasso(alpha = 0.01)
reg.fit(X_train,y_train)
print("log_revenue log_employees log_assets ")
print(reg.coef_)
| class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
Summary | print(["SVR","Lasso","Linear regression"])
err1,err2,err3 = sklearn.metrics.mean_squared_error(clf.predict(X_test),y_test),sklearn.metrics.mean_squared_error(reg.predict(X_test),y_test),sklearn.metrics.mean_squared_error(mod.predict(X_test),y_test)
print(err1,err2,err3)
print(["SVR","Lasso","Linear regression"])
err1,... | class8/class8_dimensionality_reduction.ipynb | jgarciab/wwd2017 | gpl-3.0 |
Hessian function for marking corners | # inputt -the input image name
# s -Standard Deviation value
# t -The threshold of eigen value to be considered as edge
def hessian(inputt,s,t):
start = time.time()
I = array(Image.open(inputt).convert('L')) # reads the input image into I
G = []
for i in range(-2,2+1):
G.append(gfilter(i,0... | PA1-Q3-1.ipynb | srikarpv/CV_PA1 | mit |
Links | %%HTML
<a href="http://beyond.io"> This link will take you on a journey to the beyond!</a>
%%HTML
<a href="http://unsplash.com">
<img width=400px src="https://images.unsplash.com/photo-1460400355256-e87506dcec4f?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=f35997a68b394f08caf7d46cf2d27791"/>
<p> Here I've made this ent... | unit_17/lectures/lecture_2.ipynb | whitead/numerical_stats | gpl-3.0 |
Content Arrangement
Spans, divs and breaks are ways to arrange content. They do not do much alone. Instead you use javascript and CSS to manipulate them. For example, divs are how jupyter notebooks separate input cells, from the notebook, from the top, etc.
Inspecting Tools
The best way to learn HTML is to look at diff... | %%HTML
<h1> This is a header</h1>
<style>
h1 {
color:red;
}
</style> | unit_17/lectures/lecture_2.ipynb | whitead/numerical_stats | gpl-3.0 |
Wow
Notice it made all headers red
In order to finely tune the connection between CSS, JS and HTML, there is something called selectors. | %%HTML
<h1 class="attention-getter"> This is an important header</h1>
<style>
.attention-getter {
color:blue;
}
</style> | unit_17/lectures/lecture_2.ipynb | whitead/numerical_stats | gpl-3.0 |
There is an established philosophy that HTML = content, CSS = style. Therefore, it's incorrect to create a class called "blue-class" because now you've spilled over some style into your HTML.
<span class="attention-getter"> Testing out you're own stuff</span>
So with spans and divs, we're able to attach classes to HTML... | %%HTML
<h3 class="grab-me"> This header will change soon</h3>
%%javascript
var grabme = document.querySelector('.grab-me');
grabme.textContent = 'Hoopla';
%%HTML
<ul class="fill-me"> </ul>
%%javascript
var fruits = ['strawberry', 'mango', 'bannana'];
fruits.forEach(function(i) {
document.querySelector('.fil... | unit_17/lectures/lecture_2.ipynb | whitead/numerical_stats | gpl-3.0 |
There's a lot of stuff going on in there! Here are some differences with Python:
You need semicolins at the end of lines
The for loops syntax is different. Rather than have code below, we call a forEach function and give it a function we define right there.
We also used the innerHTML instead of textContent this time a... | %%HTML
<link href='https://fonts.googleapis.com/css?family=Roboto+Condensed:300|Oswald:400,700' rel='stylesheet' type='text/css'>
%%HTML
<style>
.rendered_html {
font-family: 'Roboto Condensed';
font-size: 125%;
}
</style> | unit_17/lectures/lecture_2.ipynb | whitead/numerical_stats | gpl-3.0 |
I can also change headings to be something different | %%HTML
<style>
.rendered_html > h1,h2,h3,h4,h5,h6 {
font-family: 'Oswald';
}
</style> | unit_17/lectures/lecture_2.ipynb | whitead/numerical_stats | gpl-3.0 |
Example 2 — Changing the background
Using the inspector, I've found that the dull gray background is from the .notebook_app. | %%HTML
<style>
.notebook_app {
background-image: url('https://images.unsplash.com/photo-1453106037972-08fbfe790762?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=cbaaa89f2c5394ff276ac2ccbfffd4a4');
background-repeat: no;
background-size: cover;
}
</style> | unit_17/lectures/lecture_2.ipynb | whitead/numerical_stats | gpl-3.0 |
Example 3 — Creating a nice results report
If you just web-search for HTML table, you'll see the syntax. Basically you have this:
```
<table>
<tr> each row </tr>
</table>
```
with more than one column:
```
<table>
<tr>
<td> row 1 column 1</td>
<td> column 2</td>
</tr>
</table>
``` | import IPython.display as display
def make_pretty_table(x, y):
html = '''
<table>
<tr> <th> x</th> <th> y </th> </tr>
'''
for xi,yi in zip(x,y):
html += '<tr> <td> {} </td> <td> {} </td> </tr> \n'.format(xi,yi)
html += '</table>'
d = display.HTML(html)
display.display(d)
x ... | unit_17/lectures/lecture_2.ipynb | whitead/numerical_stats | gpl-3.0 |
Third example: Simple rectangular section with 7 nodes
Define graph describing the section:
1) stringers are nodes with parameters:
- x coordinate
- y coordinate
- Area
2) panels are oriented edges with parameters:
- thickness
- lenght which is automatically calculated | stringers = {1:[(3*a,h),A],
2:[(2*a,h),A],
3:[(a,h),A],
4:[(sympy.Integer(0),h),A],
5:[(sympy.Integer(0),sympy.Integer(0)),A],
6:[(sympy.Rational(3,2)*a,sympy.Integer(0)),A],
7:[(3*a,sympy.Integer(0)),A]}
panels = {(1,2):t,
(2,3):t... | 06_CorrectiveSolutions-7nodes.ipynb | Ccaccia73/semimonocoque | mit |
Discretization
We load the trajectory data generated by Brownian Dynamics simulations. | h5file = "data/cossio_kl0_Dx1_Dq1.h5"
f = h5py.File(h5file, 'r')
data = np.array(f['data'])
f.close()
fig, ax = plt.subplots(figsize=(12,3))
ax.plot(data[:,0],data[:,1],'.', markersize=1)
ax.set_ylim(-8,8)
ax.set_xlim(0,250000)
ax.set_ylabel('x')
ax.set_xlabel('time')
plt.tight_layout() | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
Clearly the system interconverts between two states. We can obtain a potential of mean force from a Boltzmann inversion of the probability distribution. | fig, ax = plt.subplots(figsize=(6,4))
hist, bin_edges = np.histogram(data[:,1], bins=np.linspace(-6.5,6.5,25),\
density=True)
bin_centers = [0.5*(bin_edges[i]+bin_edges[i+1]) \
for i in range(len(bin_edges)-1)]
ax.plot(bin_centers, -np.log(hist), lw=4)
ax.set_xlim(-7,7)
ax.... | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
Instead of defining two states using an arbitrary cutoff in our single dimension, we discretize the trajectory by assigning frames to microstates. In this case we use as microstates the indexes of a grid on x. | assigned_trj = list(np.digitize(data[:,1],bins=bin_edges)) | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
In this way, the continuous coordinate x is mapped onto a discrete microstate space. | fig,ax=plt.subplots(2,1, sharex=True)
plt.subplots_adjust(wspace=0, hspace=0)
ax[0].plot(range(100,len(data[:,1][:300])),data[:,1][100:300], lw=2)
ax[1].step(range(100,len(assigned_trj[:300])),assigned_trj[100:300], color="g", lw=2)
ax[0].set_xlim(100,300)
ax[0].set_ylabel('x')
ax[1].set_ylabel("state")
ax[1].set_xlabe... | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
We then pass the discrete trajectory to the traj module to generate an instance of the TimeSeries class. Using some of its methods, we are able to generate and sort the names of the microstates in the trajectory, which will be useful later. | from mastermsm.trajectory import traj
distraj = traj.TimeSeries(distraj=assigned_trj, dt=1)
distraj.find_keys()
distraj.keys.sort() | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
Master Equation Model
After generating the discrete trajectory, we can build the master equation model, for which we use the msm module. | from mastermsm.msm import msm | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
First of all, we will create an instance of the SuperMSM class, which will be useful to produce and validate dynamical models. | msm_1D=msm.SuperMSM([distraj], sym=True) | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
For the simplest type of dynamical model validation, we carry out a convergence test to check that the relaxation times $\tau$ do not show a dependency on the lag time. We build the MSM at different lag times $\Delta$t. | for lt in [1, 2, 5, 10, 20, 50, 100]:
msm_1D.do_msm(lt)
msm_1D.msms[lt].do_trans(evecs=True)
msm_1D.msms[lt].boots() | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
We then check the dependence of the relaxation times of the system, $\tau$ with respect to the choice of lag time $\Delta t$. We find that they are very well converged even from the shortest value of $\Delta t$. | tau_vs_lagt = np.array([[x,msm_1D.msms[x].tauT[0], msm_1D.msms[x].tau_std[0]] \
for x in sorted(msm_1D.msms.keys())])
fig, ax = plt.subplots()
ax.errorbar(tau_vs_lagt[:,0],tau_vs_lagt[:,1],fmt='o-', yerr=tau_vs_lagt[:,2], markersize=10)
#ax.fill_between(10**np.arange(-0.2,3,0.2), 1e-1, 10**np.arange(-0.2... | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
While this is not the most rigorous test we can do, it already gives some confidence on the dynamical model derived. We can inspect the count and transition matrices at even the shortest lag time | lt=1 # lag time
msm_1D.do_msm(lt)
msm_1D.msms[lt].do_trans(evecs=True)
msm_1D.msms[lt].boots()
plt.figure()
plt.imshow(np.log10(msm_1D.msms[lt].count), interpolation='none', \
cmap='viridis_r', origin='lower')
plt.ylabel('$\it{j}$')
plt.xlabel('$\it{i}$')
plt.title('Count matrix (log), $\mathbf{N}$')
plt.colorbar(... | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
Analysis of the results
The spectrum of relaxation times, $\tau_i$, derived from the eigenvalues of the transition matrix, is also remarkable. This system is expected to have a unique slow mode, corresponding to the barrier crossing process between the wells. In fact, that is precisely what we find. | fig, ax = plt.subplots()
ax.errorbar(range(1,len(msm_1D.msms[lt].tauT)+1),msm_1D.msms[lt].tauT, fmt='o-', \
yerr= msm_1D.msms[lt].tau_std, ms=10)
ax.fill_between(range(1,len(msm_1D.msms[1].tauT)+1), \
np.array(msm_1D.msms[lt].tauT)+np.array(msm_1D.msms[lt].tau_std), \
np.array(msm_1D.msms[lt... | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
From the eigenvectors we can also retrieve valuable information. The zeroth eigenvector, $\Psi^R_0$, corresponds to the equilibrium distribution. The slowest mode in our model, captured by the first eigenvector $\Psi^R_1$, corresponds to the transition betweem the folded and unfolded states of the protein. | fig, ax = plt.subplots(2,1, sharex=True)
ax[0].plot(-msm_1D.msms[1].rvecsT[:,0])
ax[0].fill_between(range(len(msm_1D.msms[1].rvecsT[:,0])), \
-msm_1D.msms[1].rvecsT[:,0], 0, alpha=0.5)
#ax[0].set_ylim(0,0.43)
ax[1].plot(msm_1D.msms[1].rvecsT[:,1])
ax[1].axhline(0,0,25, c='k', ls='--', lw=1)
ax[1].fi... | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
Calculation of committors
Using the method by Berezhkovskii, Hummer and Szabo (JCP, 2009), we calculate the value of the committor (or $p_{fold}$ in the context of protein folding), the probability that the system will go from to one state before going back to the other. For this we must first define microstates which ... | msm_1D.msms[1].do_rate()
FF = list(range(19,22,1))
UU = list(range(4,7,1))
msm_1D.msms[1].do_pfold(FF=FF, UU=UU)
msm_1D.msms[1].peqT
fig, ax = plt.subplots()
ax.set_xlim(0,25)
axalt = ax.twinx()
axalt.plot(-np.log(msm_1D.msms[1].peqT), alpha=0.3, c='b')
axalt.fill_between(range(len(msm_1D.msms[1].rvecsT[:,1])), \
... | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
Sensitivity analysis
Using the methods described in De Sancho et al (JCTC, 2015), we calculate the value of the sensitivity parameter, indicating the changes in the global rate (actually, on $\ln(k_{UU\rightarrow FF}$)) upon changes in the free energy of each microstate. | msm_1D.msms[1].sensitivity(FF=FF, UU=UU)
plt.plot(msm_1D.msms[1].d_lnkf, 'k', lw=3)
plt.fill_between([FF[0], FF[-1]], \
0.2, -0.1, alpha=0.15, color='green')
plt.fill_between([UU[0], UU[-1]], \
0.2, -0.1, alpha=0.15, color='red')
plt.xlabel('state')
plt.ylabel(r'$\alpha$')
plt.x... | examples/brownian_dynamics_1D/1D_smFS_MSM.ipynb | daviddesancho/MasterMSM | gpl-2.0 |
Get some data to play with | from sklearn.datasets import load_digits
digits = load_digits()
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(digits.data,
digits.target)
X_train.shape | First Steps.ipynb | amueller/nyu_ml_lectures | bsd-2-clause |
3) Apply / evaluate | print(svm.predict(X_test))
svm.score(X_train, y_train)
svm.score(X_test, y_test) | First Steps.ipynb | amueller/nyu_ml_lectures | bsd-2-clause |
<h3 style="color:#1f77b4">Calling CAS Actions</h3> | conn.serverstatus()
conn.userinfo()
conn.help(); | python/AX2016/Using Python With SAS Cloud Analytic Services (CAS).ipynb | sassoftware/sas-viya-programming | apache-2.0 |
<h3 style="color:#1f77b4"> Loading Data </h3> | tbl2 = conn.read_csv('https://raw.githubusercontent.com/'
'sassoftware/sas-viya-programming/master/data/cars.csv',
casout=conn.CASTable('cars'))
tbl2 | python/AX2016/Using Python With SAS Cloud Analytic Services (CAS).ipynb | sassoftware/sas-viya-programming | apache-2.0 |
<h3 style="color:#1f77b4"> CASTable </h3>
<br/>
CASTable objects contain a reference to a CAS table as well as filtering and grouping options, and computed columns. | conn.tableinfo()
tbl = conn.CASTable('attrition')
tbl.columninfo()
tbl2?
tbl2.fetch() | python/AX2016/Using Python With SAS Cloud Analytic Services (CAS).ipynb | sassoftware/sas-viya-programming | apache-2.0 |
<h3 style="color:#1f77b4"> Exploring Data </h3> | tbl.summary()
tbl.freq(inputs='Attrition') | python/AX2016/Using Python With SAS Cloud Analytic Services (CAS).ipynb | sassoftware/sas-viya-programming | apache-2.0 |
<h3 style="color:#1f77b4"> Building Analytical Models </h3> | conn.loadactionset('regression')
conn.help(actionset='regression');
output = tbl.logistic(
target='Attrition',
inputs=['Gender', 'MaritalStatus', 'AccountAge'],
nominals = ['Gender', 'MaritalStatus']
)
output.keys()
output
from swat.render import render_html
render_html(output) | python/AX2016/Using Python With SAS Cloud Analytic Services (CAS).ipynb | sassoftware/sas-viya-programming | apache-2.0 |
<h3 style="color:#1f77b4"> Pandas-style DataFrame API </h3>
<br/>
Many Pandas DataFrame features are available on the CASTable objects. | import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/'
'sassoftware/sas-viya-programming/master/data/cars.csv')
df.describe()
tbl2.describe()
tbl2.groupby('Origin').describe()
tbl[['Gender', 'AccountAge']].head() | python/AX2016/Using Python With SAS Cloud Analytic Services (CAS).ipynb | sassoftware/sas-viya-programming | apache-2.0 |
<h3 style="color:#1f77b4"> Visualization </h3> | from bokeh.plotting import show, figure
from bokeh.charts import Bar
from bokeh.io import output_notebook
output_notebook()
output1 = tbl.freq(inputs=['Attrition'])
p = Bar(output1['Frequency'], 'FmtVar',
values='Frequency',
color="#1f77b4",
agg='mean',
title="",
xlabel = "... | python/AX2016/Using Python With SAS Cloud Analytic Services (CAS).ipynb | sassoftware/sas-viya-programming | apache-2.0 |
conn.tableinfo()
tbl2.groupby(['Origin', 'Type']).describe()
tbl2[['MPG_CITY', 'MPG_Highway', 'MSRP']].describe()
tbl2[(tbl2.MSRP > 90000) & (tbl2.Cylinders < 12)].head() | python/AX2016/Using Python With SAS Cloud Analytic Services (CAS).ipynb | sassoftware/sas-viya-programming | apache-2.0 | |
conn.runcode(code='''
data cars_temp;
set cars;
sqrt_MSRP = sqrt(MSRP);
MPG_avg = (MPG_city + MPG_highway) / 2;
run;
''')
conn.tableinfo()
conn.loadactionset('fedsql')
conn.fedsql.execdirect(query='''
select make, model, msrp,
mpg_highway from cars
where msrp > 80000 a... | python/AX2016/Using Python With SAS Cloud Analytic Services (CAS).ipynb | sassoftware/sas-viya-programming | apache-2.0 | |
Get a list of URLs 获取URL的列表
Search and scroll 搜索并翻看
Go to Google Images and search for the images you are interested in. The more specific you are in your Google Search, the better the results and the less manual pruning you will have to do.<br>
打开Google Images页面,搜索你感兴趣的图片。你在搜索框中输入的信息越精确,那么搜索的结果就越好,而需要你手动处理的工作就越少。
Scro... | folder = 'black'
file = 'urls_black.csv'
folder = 'teddys'
file = 'urls_teddys.csv'
folder = 'grizzly'
file = 'urls_grizzly.csv' | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
You will need to run this cell once per each category.<br>
下面的单元格,每一个品种运行一次。 | path = Path('data/bears')
dest = path/folder
dest.mkdir(parents=True, exist_ok=True)
path.ls() | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
Finally, upload your urls file. You just need to press 'Upload' in your working directory and select your file, then click 'Upload' for each of the displayed files.<br>
最后,上传你的url文件。你只需要在工作区点击“Upload”按钮,然后选择你要上传的文件,再点击“Upload”即可。
Download images 下载图片
Now you will need to download your images from their respective urls... | classes = ['teddys','grizzly','black']
download_images(path/file, dest, max_pics=200)
# If you have problems download, try with `max_workers=0` to see exceptions:
download_images(path/file, dest, max_pics=20, max_workers=0) | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
Then we can remove any images that can't be opened: <br>
然后我们可以删除任何不能打开的图片: | for c in classes:
print(c)
verify_images(path/c, delete=True, max_size=500) | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
View data 浏览数据 | np.random.seed(42)
data = ImageDataBunch.from_folder(path, train=".", valid_pct=0.2,
ds_tfms=get_transforms(), size=224, num_workers=4).normalize(imagenet_stats)
# If you already cleaned your data, run this cell instead of the one before
# 如果你已经清洗过你的数据,直接运行这格代码而不是上面的
# np.random.seed(42)
# data = ImageDataBunc... | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
Good! Let's take a look at some of our pictures then.<br>
好!我们浏览一些照片。 | data.classes
data.show_batch(rows=3, figsize=(7,8))
data.classes, data.c, len(data.train_ds), len(data.valid_ds) | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
Train model 训练模型 | learn = cnn_learner(data, models.resnet34, metrics=error_rate)
learn.fit_one_cycle(4)
learn.save('stage-1')
learn.unfreeze()
learn.lr_find()
learn.recorder.plot()
learn.fit_one_cycle(2, max_lr=slice(3e-5,3e-4))
learn.save('stage-2') | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
Interpretation 结果解读 | learn.load('stage-2');
interp = ClassificationInterpretation.from_learner(learn)
interp.plot_confusion_matrix() | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
Cleaning Up 清理
Some of our top losses aren't due to bad performance by our model. There are images in our data set that shouldn't be.<br>
某些最大误差,不是由于模型的性能差导致的,而是由于数据集中的有些图片本身存在问题才导致的。
Using the ImageCleaner widget from fastai.widgets we can prune our top losses, removing photos that don't belong.<br>
从fastai.widgets库中导... | from fastai.widgets import * | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
First we need to get the file paths from our top_losses. We can do this with .from_toplosses. We then feed the top losses indexes and corresponding dataset to ImageCleaner.<br>
首先,我们可以借助.from_toplosses,从top_losses中获取我们需要的文件路径。随后喂给ImageCleaner误差高的索引以及对应的数据集参数。
Notice that the widget will not delete images directly from ... | db = (ImageList.from_folder(path)
.no_split()
.label_from_folder()
.transform(get_transforms(), size=224)
.databunch()
)
# If you already cleaned your data using indexes from `from_toplosses`,<br><br>
# 如果你已经从`from_toplosses`使用indexes清理了你... | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
Then we create a new learner to use our new databunch with all the images.<br>
接下来,我们要创建一个新的学习器来使用包含全部图片的新数据堆。 | learn_cln = cnn_learner(db, models.resnet34, metrics=error_rate)
learn_cln.load('stage-2');
ds, idxs = DatasetFormatter().from_toplosses(learn_cln) | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
Make sure you're running this notebook in Jupyter Notebook, not Jupyter Lab. That is accessible via /tree, not /lab. Running the ImageCleaner widget in Jupyter Lab is not currently supported.<br>
确保你在Jupyter Notebook环境下运行这个notebook,而不是在Jupyter Lab中运行。我们可以通过/tree来访问(notebook),而不是/lab。目前还不支持在Jupyter Lab中运行ImageCleaner小工具... | ImageCleaner(ds, idxs, path) | zh-nbs/Lesson2_download.ipynb | fastai/course-v3 | apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.