Skip to content

Instantly share code, notes, and snippets.

View CharlesRajendran's full-sized avatar
:octocat:
Living

Charles's Labs CharlesRajendran

:octocat:
Living
View GitHub Profile
@CharlesRajendran
CharlesRajendran / script.js
Created October 21, 2017 09:31
grunt setup
module.exports = function(grunt) {
grunt.initConfig({
});
}
grunt.initConfig({
jshint: {
all:['sample.js']
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
# get the features and labels
features = np.array(iris_dataset.data, dtype="float64")
labels = np.array(iris_dataset.target, dtype="float64")
# combine featutre with labels to shuffle the ordered data
data = np.column_stack((features, labels))
np.random.shuffle(data)
# preparing dataset and label dataset
X = data[:, :-1]
from sklearn import datasets
import numpy as np
iris_dataset = datasets.load_iris()
# training and testing set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2)
# train the model
from sklearn import neighbors
clf = neighbors.KNeighborsClassifier(n_neighbors=5)
clf.fit(X_train, y_train)
# accuracy testing
from urllib.request import urlopen
# read the page
url = urlopen('http://www.cricbuzz.com/cricket-news/100707/destinys-child-zimbabwes-middle-order-batsman-sikandar-raza-treats-triumphs-and-failures-the-same')
html = url.read()
url.close()
# create beautiful soup object and parse the html so we can use bs methods
import bs4
bs = bs4.BeautifulSoup(html, 'html.parser')
title = bs.title
# output - <title itemprop="name">Destiny's child, Raza treats triumphs and failures the same | Cricbuzz.com</title>
title_text = title.getText()
# output - Destiny's child, Raza treats triumphs and failures the same | Cricbuzz.com