Jupyter notebook into post
download jupyter notebook as html,
add that html source code to XYZ Html
embed that to post like
In [1]:
import numpy as np
from bokeh.plotting import figure, show, output_file
from bokeh.io import output_notebook
N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = ["#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y)]
In [2]:
output_notebook()
In [3]:
p = figure()
p.scatter(x, y, radius=radii,
fill_color=colors, fill_alpha=0.6,
line_color=None)
# output_file("color_scatter.html", title="color_scatter.py example")
show(p) # open a browser
In [ ]:
In [1]:
import pandas as pd
import matplotlib.pyplot as plt
from time import time
%matplotlib inline
plt.rcParams['figure.figsize'] = (1.5, 1.5) # set default size of plots
# plt.rcParams['image.interpolation'] = 'nearest'
# plt.rcParams['image.cmap'] = 'gray'
In [2]:
from sklearn.decomposition import PCA, RandomizedPCA, randomized_svd
from sklearn.cluster import KMeans
from sklearn.manifold import Isomap
from sklearn.model_selection import train_test_split, KFold
In [3]:
train=pd.read_csv('train.csv')
test=pd.read_csv('test.csv')
train.shape,test.shape
Out[3]:
In [4]:
train.head(1)
Out[4]:
In [5]:
test.head(1)
Out[5]:
In [9]:
label=train.pop('label')
In [7]:
def fuckpca(train,test,n):
start=time()
pca=PCA(n_components=n,whiten=True)
train=pca.fit_transform(train)
test=pca.transform(test)
print 'used {:.2f}s'.format(time()-start)
return train,test
In [8]:
train_pca,test_pca=fuckpca(train,test,36)
In [9]:
train_pca.shape,test_pca.shape
Out[9]:
In [10]:
plt.imshow(train_pca[3].reshape(6,-1))
Out[10]:
In [11]:
from sklearn.ensemble import GradientBoostingClassifier, GradientBoostingRegressor
In [12]:
model=GradientBoostingClassifier(verbose=1,n_estimators=300)
model
Out[12]:
In [99]:
start=time()
model.fit(train_pca,label)
print 'used {:.2f}s'.format(time()-start)
In [100]:
result=model.predict(test_pca)
In [ ]:
In [13]:
def save():
import numpy as np
submit=pd.DataFrame({'ImageId':np.arange(1,len(result)+1),'Label':result})
submit.to_csv('gbc.csv',index=False)
In [14]:
# sub=pd.concat([pd.Series(np.arange(1,len(result)+1)),pd.Series(result)],axis=1)
# sub.columns=['ImageId','Label']
In [108]:
model.score(after,label)
Out[108]:
In [115]:
tr=model.predict(after)
In [128]:
(tr==label).sum()/float(label.shape[0])
Out[128]:
In [129]:
from sklearn.metrics import confusion_matrix
In [ ]:
In [4]:
from sklearn.svm import SVC
In [5]:
svc=SVC(verbose=1)
svc
Out[5]:
In [7]:
train_pca=train
test_pca=test
In [10]:
start=time()
svc.fit(train_pca,label)
print 'used {:.2f}s'.format(time()-start)
In [19]:
result=svc.predict(test_pca)
In [21]:
save()
In [17]:
from sklearn import svm,datasets
from sklearn.model_selection import GridSearchCV
In [13]:
iris = datasets.load_iris()
iris.data[0:4]
Out[13]:
In [14]:
parameters = {'kernel':('linear', 'rbf'), 'C':[1, 5, 10]}
In [15]:
model = svm.SVC()
In [18]:
classifier =GridSearchCV(model, parameters)
In [19]:
classifier.fit(iris.data, iris.target)
Out[19]:
In [20]:
classifier.best_params_
Out[20]:
In [37]:
# classifier.cv_results_
In [38]:
classifier.best_estimator_
Out[38]:
In [24]:
import scipy
In [33]:
print scipy.stats.expon(scale=100)
In [ ]:
In [39]:
parameter_dist = {
'C': scipy.stats.expon(scale=100),
'kernel': ['linear'],
'gamma': scipy.stats.expon(scale=.1),
}
In [119]:
classifier = grid_search.RandomizedSearchCV(model, parameter_dist)
classifier.fit(iris.data, iris.target)
Out[119]:
In [120]:
classifier.best_params_, classifier.best_score_
Out[120]:
In [63]:
wtf=scipy.stats.expon(scale=10)
In [66]:
print wtf.rvs(5)
In [ ]:
wtf.rvs
In [ ]: