"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

November 26, 2016

Day #42 - Classes in python

Today it's bit more on classes in python. It is similar to C# / C++ / Java


import pandas as pd
import random
class DemoClass:
#Class members
df = pd.DataFrame()
a = []
#Initialization
def __init__(self):
self.df = pd.DataFrame({'A':[1,2,3,4],'B':[5,6,7,8]})
for i in range(1,56):
self.a.append(i)
print('Initialized values')
print(self.df)
print(self.a)
#Custom methods modify
def modify(self):
self.df = self.df.drop('A',1)
print('Modified df')
print(self.df)
#Custom methods reinitialize
def reinitialize(self):
print('Reinitialized')
self.df = pd.DataFrame({1:[1,2,3,4],2:[1,2,3,4],10:[1,2,3,4]})
self.df = self.df.drop(1,1)
#Custom methods displaydata
def displaydata(self):
print('In Display Data')
print(random.sample(self.a,15))
print(self.df)
#Object Creation
x = DemoClass()
#Methods Invocation
x.displaydata()
x.modify()
x.displaydata()
x.reinitialize()
x.displaydata()
view raw classexample.py hosted with ❤ by GitHub

November 11, 2016

Day #41 - Machine Learning Interesting Qns


I do read through a lot of materials. Some readings are very clear and needs bookmark. Some of those questions and answers
  1. How does KNN predict class label for new example ?
    • Find the nearest K neighbour of example which needs to be classified. Take the major vote based on class labels of the K neighbours found
  2. Classification - Map input to discrete outputs
  3. Generative Model - Naive Bayes
  4. Discriminative Model - SVM, Decision Trees, Neural Networks, Boosting, KNN
  5. Regression - Map input to continuous outputs
  6. Decision Tress - Embedded Implicit Feature Selection method
  7. PCA
    • Taking Data into a new space
    • Number of Eigen Values = Number of original dimensions
    • Pick the top k Eigen Value Vectors

       8. Linearly non-separable in normal plane. With SVM Kernal Technique we can project it in hyper plane and make it linearly separable

       
       9. Linearly Separable

Happy Learning!!!

November 05, 2016

Day #40 - Download Images from Web using Python

This post is about downloading images from a URL
  • Read from the input file
  • Perform recursive download for all files
  • Try catch handled errors and downloaded file successfully


import urllib.request
#Read file tab spaced
f = open("facescrub_actresses.txt",'r')
readlines = f.readlines()
i = 1
title = "female"
for line in readlines:
name = title + str(i) + ".jpg"
i = i+1
#Download only 300 images
if(i==300):
break
values = line.split('\t')
print('Imagepath-',values[3])
try:
#Download Image to directory
urllib.request.urlretrieve(values[3],name)
except:
print("Error for",values[3])