Python

learn Python By Example – Basic Operations With NumPy Array

Basic Operations With NumPy Array /* Import modules */ import numpy as np /* Create an array */ civilian_deaths = np.array([4352, 233, 3245, 256, 2394]) civilian_deaths array([4352, 233, 3245, 256, 2394]) /* Mean value of the array */ civilian_deaths.mean() 2096.0 /* Total amount of deaths */ civilian_deaths.sum() 10480 /* Smallest value in the array */ …

learn Python By Example – How to Apply Functions To List Items

Applying Functions To List Items Create a list of regiment names regimentNames = [‘Night Riflemen’, ‘Jungle Scouts’, ‘The Dragoons’, ‘Midnight Revengence’, ‘Wily Warriors’] Using A For Loop Create a for loop goes through the list and capitalizes each /* create a variable for the for loop results */ regimentNamesCapitalized_f = [] /* for every item …

learn Python By Example – How to Find All Combinations For A List Of Objects

All Combinations For A List Of Objects Preliminary /* Import combinations with replacements from itertools */ from itertools import combinations_with_replacement Create a list of objects /* Create a list of objects to combine */ list_of_objects = [‘warplanes’, ‘armor’, ‘infantry’] Find all combinations (with replacement) for the list /* Create an empty list object to hold …

Machine Learning for Beginners in Python: K-Nearest Neighbors Classification

K-Nearest Neighbors Classification Preliminaries import pandas as pd from sklearn import neighbors import numpy as np %matplotlib inline import seaborn Create Dataset Here we create three variables, test_1 and test_2 are our independent variables, ‘outcome’ is our dependent variable. We will use this data to train our learner. training_data = pd.DataFrame() training_data[‘test_1’] = [0.3051,0.4949,0.6974,0.3769,0.2231,0.341,0.4436,0.5897,0.6308,0.5] training_data[‘test_2’] = [0.5846,0.2654,0.2615,0.4538,0.4615,0.8308,0.4962,0.3269,0.5346,0.6731] training_data[‘outcome’] = …