Friday, May 25, 2018

Classification using NaiveBayse Algorithm using Python

#Import Library of Gaussian Naive Bayes model
from sklearn.naive_bayes import GaussianNB
import numpy as np
import pandas as pd
 
#assigning predictor and target variables
dataF = pd.DataFrame()
dataF["x1"] = np.random.random_sample((5,)) + 1
dataF["x2"] = np.random.random_sample((5,)) + 2 

dataL = pd.DataFrame()
dataL = np.array([3, 3, 4, 3, 4])
 
#Create a Gaussian Classifier
model = GaussianNB()

# Train the model using the training sets 
model.fit(dataF, dataL)

#Predict Output 
predicted= model.predict([[1,2],[3,4]])
print(predicted)

Output: ([3,4])
 
-Thank you 

Wednesday, May 23, 2018

Basic Panda's functions for dataset manipulation in Python


Let we have two tables
Data1.schema:
    name:
    Company:
    Address:
Data2.schema:
    Name:
    gender:
    Age:

Commands:


# delete a column

del Data1[“name”]

# Return all the rows of the ‘name’ column

data1.loc[:, ‘name’]

# Return all the rows from ‘name’ column to ‘Company’ column

data1.loc[:, ‘name’:’Company’]

# Return all the rows from ‘Company’ column to ‘Address’ column

data1.loc[:, ‘Company’:’Address’]

# Return the rows whose Address is “India”

data1.loc[lambda var: var.Address == “India”, : ]
or
data1.loc[data1[“Address”] == “India”, :]

# Return only the name whose Address is “India”

data1.loc[lambda var: var.Address == “India”, ’name’]

# Return only the first five names whose Address is “India”

data1.loc[lambda var: var.Address == “India”, ’name’].head(5)

# Return only the last five names whose Address is “India”

data1.loc[lambda var: var.Address == “India”, ’name’].tail(5)

# Return the list of unique Addresses

data1.Address.unique()

# Return the list of unique Companies

data1.Company.unique()

# Return the list of unique names

data1.name.unique()

# Return the first unique Address

data1.Address.unique()[0]

# Return the total number of unique Addresses

data1.Address.unique().size

# Return the name, age and gender from data2 if the Address is India

t = data1.loc[data1[“Address”] == “India”, “name”].unique()
for x in range(0,t.size)
    data[2].loc[data2[“name”]==t[x],:]

Wednesday, May 2, 2018

Accessing remote GUI application using PuTTY

Extending the post in here, today we will see how the remote GUI applicaiton can be accessed using X server and the PuTTY.

Remote Server configuration:
  •     Ubuntu 16.04
  •     OpenSSH-server
Client machine configuration:
  •     Windows 8 or later
  •     Xming software tool

Remote server setup:
Install openssh-server package by executing following command:
sudo apt-get install openssh-server

Client machine setup:
  • Download Xming for Windows 8 64bit.
  • Install Xming executable file. You don't have to do any changes. Leave everything to the default selection.
  • Download and install the latest verion of the PuTTY from here.

  • Run Xming from the start menu or Issue the following command in command prompt
cd "c:\Program Files (x86)\Xming"
Xming.exe -multiwindow 
  •  Run PuTTY
  • In the PuTTY configuration window enter the IP address, port and select SSH radio button.

  • Select SSH from Connection category.
  • Check "Enable X11 forwarding" option and click on Open button. 


  • In the consol, now enter "gnome-calculator" to verify the above steps.
    Instead of  "gnome-calculator", you can enter command to access remote GUI application.
    I assume that, you know how to open your application from command line/ terminal.


Thats all for now.  


-Thanks