3. Course coverage
⢠Data collection
⢠Google form
⢠Data processing and analysis
⢠Python, SPSS, WEKA, MS Excel
⢠Report writing
⢠MS Word, Latex
⢠Reference organization
⢠MS Word, Mendeley
3
5. Presentation Assignment
Topic (present date) To Do Who?
1.Collect Data using
Google form (Mon
April 1)
Creating questionnaire (with multiple question
types) using Google form; save data; show
results
2. Latex (Mon April 1) Document preparation; insert formats,
equations, images, tables, references
3. Data analysis in MS
Excel (Wed April 3)
Data processing & data analysis such as filtering,
pivot table, dashboard, regression analysis; data
visualization
4. Explore Reference
Tab of MS Word
(Wed April 3)
Creating table of content; list of tables & figures;
Reference management
5. Mendeley (Thu
April 4)
Reference management by collecting from
different sources; Citation
6. SPSS (Thu April 4) Create data set; data preprocessing; descriptive
& inferential data analysis; generate plots
7. WEKA (Fri April 5) Data preprocessing; explore classification &
clustering algorithms
8. Python Data preprocessing (Pandas); explore learning
algorithms (sklearn); visualization (matplotlib)
6. Google Forms provides a customized, straightforward solution
to help collect large amounts of data from various sources at
the same time. Whatâs more, as part of the Google G Suite,
Google Forms can easily be integrated with other Google tools,
including Google Sheets.
7. Google Forms
â Data collection is the first step in any project,
research activities, whether youâre investigating
â course delivery,
â student satisfaction, or
â Customer need, etc. âŚ
â You can design a questionnaire using Google
forms
â Google Forms offer a range of features and
settings.
â These allow you to collect, manage and optimize
large, complex data that will help you to conduct
data analysis to find solution for a given problem.
8. Why use Google Forms?
â Data
â Everyone wants data!
â Google Forms is a data gathering and tracking
form that is free and easy to learn
9. Google Forms
⢠Google Forms is an online form generator tool
that you can use to collect a variety of data
quickly.
⢠You can create your own custom forms using
ďź the variety of question types (multiple choice,
short or long answer, dropdown, linear scale,
etc.) Google provides, as well as
ďź a variety of settings to make the form
personalized to your research or project.
10. How to create a Google Form
1. Create a new form
â Open https://docs.google.com/forms/ or access the tool
via Google Apps in Chrome. You can either start with a
ready-made template by Google, or start from scratch.
â To start from scratch, letâs use the Blank option to begin.
11. Start creating Google Form
â Here, you can start by adding the form name
and form description.
12. Add questions
â To add a new question to your form, click on the plus icon
located on the right-hand side of your form.
â A new question box should appear. Here, you can use the
dropdown menu on the right to choose your question type.
Then, use the fields to write out your question, and (if
applicable), write out your answer options.
â Google form supports different kinds of questions, such as
â Short answer, Long answer, Multiple choice, Check boxes,
Drop down menu, More...
â To make the question mandatory, activate the Required button
located at the bottom of the question box.
â If you want to move your answer options around, you can drag
and drop them by hovering over the left of each answer option.
â Continue adding all of your questions.
13. Add sections
â If your Google Form is quite long, you may want to section it
off based on different categories. I
â For example, you can divide the survey into sections, like student
profile, course satisfaction, etc.
â Click on the question before you want your section to start. Select
the Add section icon from the menu on the right-hand side.
â The section should appear below. Add a title and brief description.
â Customize your form
â Click on the Customize theme button on the top right-hand side of
the screen. Here, you can adjust the theme of your form:
â Add a header image
â Choose your theme color and background color
â Adjust the font
â Under the Settings tab, you can further customize your form.
â You can turn it into a quiz for example, and manage how your
responses will be collected and analyzed.
â Simply select a question and use the menu on the right-hand side
to add an image, add a video, or import existing questions.
14. Collect responses
â With your Google Form ready, itâs time to determine where to
send the responses.
â Click on the Responses tab, then the More options (âŽ) button.
Choose Select responses destination from the dropdown.
â Here, choose whether to save your responses in a new or existing
spreadsheet.
â Let us create a new spreadsheet. Add the name of your new
spreadsheet.
â Once finished, click Create.
â There should now be a Google Sheets icon next to the More
options (âŽ) button. Click this to open the new spreadsheet.
â Send to user
â Click the purple Share button located on the top right-hand side
of the screen.
â You can do the following:
â Add email addresses individually.
â Copy the Google Form link to add to a message.
â Copy a HTML link to embed the form in an email or website page.
â Once youâve carried out your preferred method, click
the Send or Copy button to finalize the process.
15. Mini Assignment
()
â Use Google form as per your interest
â create questionnaire (with at least four question types,
with multiple sections),
â send it to respondents for collecting data (ask the class
or friends to fill it)
â Produce two pages report:
â where you present summary of the response using bar
chart, pie chart, line graph or any other
â âDownload the collected data in .csv format and attach
it with the report
17. What is Latex?
â LATEX is a tool for typesetting professional-looking
documents.
â Arguments in favor of LATEX include:
â support for typesetting extremely complex
mathematics, tables and technical content for the
physical sciences;
â facilities for footnotes, cross-referencing and
management of bibliographies;
â ease of producing complicated, or tedious, document
elements such as table of contents, lists of figures;
â being highly customizable for personalized document
production due to its intrinsic programmability and
extensibility through thousands of free add-on
packages.
18. Writing your first piece of LATEX
â Letâs start with the simplest working example,
which can be opened directly in Overleaf:
documentclass{article}
begin{document}
First document. This is a simple example, with no
extra details included.
end{document}
19. Including title, author & date information
documentclass[12pt, letterpaper]{article}
title{My first LaTeX document}
author{Million M }
date{December 2023}
begin{document}
maketitle
We have now added a title, author and date to
our first LaTeX{} document!
end{document}
20. Bold, italics and underlining
â text formatting commands:
â Bold: bold text in LaTeX is typeset using the textbf{...} command.
â Italics: italicised text is produced using the textit{...} command.
â Underline: to underline text use the underline{...} command.
documentclass[12pt, letterpaper]{article}
title{My first LaTeX document}
author{Million M }
date{December 2023}
begin{document}
maketitle
Some of the greatest emph{discoveries} in science were made by
accident.
textit{Some of the greatest emph{discoveries} in science were made by
accident.}
textbf{Some of the greatest emph{discoveries} in science were made by
accident.}
end{document}
21. Adding math to LATEX
To typeset inline-mode math you can use one of these
delimiter pairs: ( ... ), $ ... $ or begin{math} ...
end{math}, as demonstrated in the following
example:
documentclass[12pt, letterpaper]{article}
begin{document}
In physics, the mass-energy equivalence is stated by the
equation $E=mc^2$, discovered in 1905 by Albert
Einstein.
end{document}
See the difference between; (i) ( ... ) and [ ... ]
[sum_{n=0}^{n} x^2]
22. Chapters and sections
â Collectively, LaTeX document classes provide the following sectioning
commands, with specific classes each supporting a relevant subset:
â part{part}
â chapter{chapter}
â section{section}
â subsection{subsection}
â subsubsection{subsubsection}
â paragraph{paragraph}
â subparagraph{subparagraph}
â commands used to structure a document based on the book class:
documentclass{book}
begin{document}
%tableofcontents
chapter{First Chapter}
section{Introduction} This is the first section.
section{Literature} Second Section
subsection{Related works} sub section
section*{Unnumbered Section} to let you just note
end{document}
23. Chapters and sections
â Creating tables
â The following examples show how to create tables in LaTeX, including the
addition of lines (rules) and captions.
â Creating a basic table in LATEX
â We start with an example showing how to typeset a basic table:
begin{table}
caption{list of Books}
label{book}
begin{center}
begin{tabular}{c c c c}
cell1 & cell2 & cell3
cell4 & cell5 & cell6
cell7 & cell8 & cell9
end{tabular}
end{center}
end{table}
I like table ref{book}
25. Adding figures
â Make sure that the package (usepackage{graphicx}) is included as a header nextto
document class
documentclass{article}
usepackage{graphicx}
begin{document}
First document. This is a simple example, with no extra details included.
begin{figure}
centering
includegraphics{Penguins}
caption{Caption}
label{peng}
end{figure}
I like figure ref{peng}
end{document}
26. AlsoâŚ
â As a document production tool, Try to
understand how to include in Latex
â Table of content
â List of figure and tables
â References and citations
28. Reference styles
Discipline style(s)
Business & Economics Harvard
Engineering & IT IEEE
Language & Humanities MLA; Chicago; Harvard; MHRA
Law Bluebook; OSCOLA
Medicine Vancouver; AMA; NLM
Psychology APA
Sciences ACS; Chicago; CSE; Harvard
Social sciences AAA; APA; ASA; Chicago
29. Mendeley
â Mendeley is a desktop and web program for
managing and sharing research papers,
discovering research data and collaborating online
â Mendeley is a free reference manager that can help
you collect references, organize your citations, and
create bibliographies.
â The strength of Mendeley, however, is what it adds to
that. Mendeley is also an academic social network
that enables you to share your research with others.
30. Notable features of Mendeley
â Integrates with Word, OpenOffice and BibTeX.
â Multiple ways to import and create references.
â Unique options for organizing and annotating
PDFs.
â Options to sync and collaborate across multiple
computers and with multiple people.
â Mendeley Cite allows for quick and easy citation
of materials that have been added into the
Menedeley library and to generate a full
reference
31. Steps to follow to install Mendeley
â Download âMendeley desktopâ
â Install it
â Register (if you have no account) and sign in
â Install plugin to MS word
â To easily add references to Mendeley, it is good
practice to:
â Create folder
â Organize articles you need for the report
â To change the citation style in Mendeley desktop
â Open the citation styles library by expanding the view
menu and select one of the style.
â If the style does not exist, choose âMore stylesâŚâ find
the style you wish to modify and right click on it. Now
choose the âEdit Styleâ option
32. Citation and reference
â Add files to Mendeley
â Check whether all details of the article extracted or
not; otherwise manual intervention is required
â If details of the article is missing from the paper
or if the article is not available in the folder
â Search in Google Scholar
â Click on Cite
â Download the âRefManâ
â Drag and drop to Mendley
33. To cite and refer in the report
⢠To cite articles and generate reference in MS
Word
â Go to MS-Word reference tab ď click âInsert Citationâ
ď click âgo to Mendeleyâ
â Select reference and click âCiteâ
⢠Once all the articles referred in the paper are
cited,
⢠Generate references using âInsert Bibliographyâ
â Make sure that the write style is selected
34. Mini Assignment (Due:____)
â Use Mendeley for reference management
â Assume that you have at least five articles
downloaded for reading; drag and add to mendeley
â Assume two of the articles are not downloaded
since they are not accessible for download, but you
need them to include in the reference list. Use
Google scholar to extract their citation information
â Check for completeness of the information
extracted by mendeley
â Prepare one page report and cite at least six articles
and finally list references at the end of the write up
35. SPSS
â Originally it is an acronym of Statistical Package
for the Social Science
â but now it stands for Statistical Product and Service
Solutions
36. Overview of SPSS?
â One of the most popular statistical packages
which can perform highly complex data
manipulation and analysis with simple
instructions.
â SPSS is a Windows based program that can be
used
â to perform data entry and analysis
â to create tables and graphs.
37. Basic structure of SPSS
There are two different windows in SPSS
â 1st Data Editor Window - shows data in two
forms
â Data view
â Variable view
â 2nd Output viewer Window â shows results of
data analysis
â You must save the data editor window and
output viewer window separately.
â Make sure to save both if you want to save your
changes in data or analysis.
38. Data Editor Window
â Variable view
â Rows define the variables Name, Type, Width,
Decimals, Label, Missing, Columns, Align, Measure,
Role
â Data view
â Rows are cases and Columns are variables
â Data measure
â Scale â numeric data on an interval or ratio scale,
such as age, weight, income
â Nominal â categories that cannot be ranked (ID
number)
â Ordinal â categories that can be ranked (level of
satisfaction)
39. Descriptive statistics
â Descriptive statistics are statistics that
summarizes or describe a variableâs
â central tendency: compute the âmiddleâ or expected
value
â use mean, mode and median
â Dispersion: measure the distribution or scatterness of
the data around the mean.
â Use standard deviation, variance and range
â Central Tendency
â Mean is the summation of all data values divided by
the number of data.
â Median is the datum that is in the middle of the data
when it is rank-ordered.
â The mode is the value that occurs most frequently.
40. Descriptive statistics
â Central tendencies that are appropriate for different levels of
measurement:
â Nominal: Mode
â Nominal Variables: To obtain descriptive statistics for nominal
variables, click Analyze, Descriptive Statistics, Frequencies.
Move the nominal variables that you want to examine into the
Variables box. Then click on the Statistics button & Check
âModeâ box
â E.g. sex variable
â Ordinal: Median, Mode
â Ordinal Variables: are ranked variables, like Likert scale responses. For
obtaining descriptive statistics: click Analyze, Descriptive
Statistics, Frequencies. Move the ordinal variables that you want to
examine into the Variables box. Then click on the Statistics button.
â Scale: Mean, Median, Mode
â SPSS uses the term âScaleâ for Interval and Ratio levels of measurement.
â To obtain descriptive statistics from continuous variables,
â click Analyze, Descriptive Statistics, Descriptives. Move your
variables into the Variable box. Click Options and make the
following selections
41. Descriptive statistics
â Dispersion
â measures how far the data spread out around the
âcenterâ.
â Methods like range, standard deviation, variance are
used for measuring dispersion
â You can examine dispersion by using the following:
â Scale: Range, Variance, Standard Deviation
â Ordinal: Range
â Nominal: None
42. Descriptive statistics
â Frequencies
â Click âAnalyze,â âDescriptive statistics,â then click
âFrequenciesâ
â Click variable âgenderâ and put it into the variable
box.
â Click âCharts.â Then click âBar chartsâ and click
âContinue.â
â Finally Click OK in the Frequencies box.
43. Descriptive statistics
â Descriptive analysis
â Click âAnalyze,â
âDescriptive statistics,â
then click âDescriptivesâŚâ
â Click âEducational levelâ
and âBeginning Salary,â
and put it into the
variable box. Click
Options Click
â The options allows you to
analyze other descriptive
statistics besides the
mean and Standard
deviation. Click âvarianceâ
and âkurtosisâ Finally click
âContinueâ
â Finally Click OK in the
Descriptives box. You will
be able to see the result
of the analysis.
44. Inferential analysis: Correlation
â Correlation indicates the extent to which there is relationship
between variables
â The analysis may be focused on univariate (analysis of one variable),
bivariate (analysis of relationships between two different variables)
or multivariate correlation (analysis of relationships between more
than two different variables)
â Correlation coefficients
â Correlation coefficients provide a numerical summary of the
direction and strength of the linear relationship between two
variables.
â The sign of the correlation coefficient ranges in between [-1 to 1]
which indicates the direction of the correlation:
â a positive correlation indicates that as one variable increases, so does
the other;
â a negative correlation indicates that as one variable increases, the
other decreases.
â The strength of the relationship is given by the numeric value:
â 1 indicates a perfect relationship;
â 0 indicates no relationship between the variables.
45. Obtaining Correlation coefficients
â The main correlation coefficients are:
â Pearsonâs r is a measure of association for nominal
and/or continuous variables.
â Spearman rho & Kendallâs tau-b: for ordinal level or
ranked data.
â To calculate Pearsonâs r in SPSS,
â go to Analyze, Correlate, Bivariate. Enter variables.
â Where,
â bivariate correlation determines the relationships
between two different variables (i.e., X and Y).
â Test of significance
â One-tailed tests allow for the possibility of an effect in
one direction.
â Two-tailed tests test for the possibility of an effect in
two directionsâpositive and negative
46. Result interpretation
â Note that the Pearsonâs r value for comparing age to age
is 1, suggesting perfect correlation.
â On the other hand, the Pearsonâs r value of the 2 different
variables (in this case, the value is .139), suggests that age and
watching TV are directly related; hence, someone ages, they
watch more television.
47. Inferential analysis: Regression analysis
â Correlation measure the strength of relationship
between variables, but not measure cause and effect
â Regression analysis determines the effect of one or more
independent variables on dependent variable.
The most common form
of regression analysis
is linear regression, in
which one finds the line
that most closely fits the
data according to a
specific mathematical
criterion.
Y = a + bX + Ďľ
48. Linear Regression Analysis
â SPSS provides three results
â Model summary
â R2: Coefficient of determination. It determines the
effect/impact of independent variables on dependent
variable
â The effect may be accounted for 99.5%, which means 99.5%
variation in dependent variable can be explained due to
independent variables
â ANOVA (Analysis of Variance)
â Tells model validity
â Based on sig. where if sig < 0.05 it is a good model
â Coefficients
â Take beta "B" value under the "Unstandardized
Coefficients" column, to construct the equation
â To accept and reject hypothesis
â t > 1.96 - +ve impact (accept hypothesis)
â t < -1.96 - -ve impact (reject hypothesis)
49. Linear Regression Analysis
â The first table of interest in the linear regression
analysis is the Model Summary table
â This table provides the R and R2 values.
â The R value represents the simple correlation and is
0.873, which indicates a high degree of correlation.
â The R2 value indicates how much of the total
variation in the dependent variable, Price, can be
explained by the independent variable, Income. In
this case, 76.2% variation in price can be explained
due to income.
50. ANOVA
â The next table is the ANOVA table, which reports how well the
regression equation fits the data (i.e., predicts the dependent
variable):
â This table indicates that the regression model predicts the
dependent variable significantly well. How do we know this?
Look at the "Regression" row and go to the "Sig." column.
â This indicates the statistical significance of the regression model that
was run. Here, p < 0.0005, which is less than 0.05, and indicates that,
overall, the regression model statistically significantly predicts the
outcome variable (i.e., it is a good fit for the data).
51. Prediction
â The Coefficients table provides information to predict
price from income, as well as determine whether income
contributes statistically significantly to the model (by
looking at the "Sig." column).
â Furthermore, we can use the values in the "B" column under
the "Unstandardized Coefficients" column, as shown below:
â to present the regression equation as:
Price = 8287 + 0.564(Income)
52. Assignment (Due: )
â Use SPSS for Data Analysis and prepare a report
using the following template
â Introduce SPSS
â Describe the selected data for analysis using SPSS
â You may use the data available with SPSS or any online data (but
each student is expected to use different data)
â First conduct descriptive analysis using central tendency
and variations
â Show the result and write what you understand from the result
â Second conduct inferential analysis by applying
correlation and linear regression analysis
â Show the result and write what you understand from the result
â Conclusion and one major recommendation
â Reference
54. What is WEKA?
⢠Waikato Environment for Knowledge Analysis
â Itâs a data mining/machine learning tool
developed by Department of Computer Science,
University of Waikato, New Zealand.
â Weka is also a bird found only on the islands of
New Zealand.
⢠Download and Install WEKA from:
http://www.cs.waikato.ac.nz/~ml/weka/index.html
⢠Support multiple platforms (written in java):
â Windows, Mac OS X and Linux
55. Main Features
⢠Weka includes everything necessary for
knowledge discovery and constructing models
â Covers all major knowledge discovery tasks
â Includes tools to preprocess and visualize data
⢠49 data preprocessing tools
â classification/regression algorithms
â clustering algorithms
â association rules discovery algorithms
â attribute/subset selection
56. Explorer: pre-processing the data
⢠Data can be imported from a file in various
formats: ARFF, CSV, C4.5, binary
â Data can also be read from a URL or from an SQL
database (using JDBC)
⢠Pre-processing tools in WEKA are called
âfiltersâ
⢠WEKA contains filters for:
â Discretization, normalization, resampling,
attribute selection, transformation and combining
attributes, âŚ
57. Clicking on this will bring up a list of all of
the filters, organized into a hierarchy.
Click on each folder to expand the list.
There are dozens of choices
58. Explorer: Building âclassifiersâ
⢠Weka supports all major classification and regression
methods
â Decision Trees, Rule learners, Nearest Neighbor,
NaĂŻve Bayes, support vector machines, Neural
Networks, etc.
⢠Also support ensemble classifiers:
â It combines classifiers to work together, of course,
will learn about these later
⢠Classifiers in WEKA are models for predicting nominal
or numeric quantities
59. Explorer: clustering data
⢠WEKA contains âclusterersâ for finding groups
of similar instances in a dataset
⢠Implemented schemes are:
â k-Means, EM, Cobweb, X-means, FarthestFirst
⢠Clusters can be visualized and compared to
âtrueâ clusters (if given)
⢠Evaluation based on loglikelihood if clustering
scheme produces a probability distribution
60. Explorer: finding associations
⢠WEKA contains an implementation of the
Apriori algorithm for learning association rules
â Works only with discrete data
⢠Can identify statistical dependencies between
groups of attributes:
â milk, butter ď bread, eggs (with confidence 0.9
and support 2000)
⢠Apriori can compute all rules that have a given
minimum support and exceed a given
confidence
61. Python
Python is a high-level, general-purpose programming
language. Its design philosophy emphasizes code
readability with the use of significant indentation
62. What software we need to use
python for different tasks?
⢠Anaconda
⢠Jupyter Notebook
⢠Different packages (Libraries), such as scikit-
learn, opencv, numpy, pandas, etc.
63. Installing Anaconda on Windows
⢠Anaconda is a package manager, an environment manager,
and Python distribution that contains a collection of many
open source packages.
ďźThis is advantageous, when you are working on a project,
you may need many different packages (scikit-learn, numpy,
scipy, pandas to name a few), which an installation of
Anaconda comes preinstalled with.
⢠If you need additional packages after installing Anaconda,
you can use
ďźAnaconda's package manager, conda, or
ďźpip to install those packages (pip install PACKAGE).
ďźThis is highly advantageous as you don't have to manage
dependencies between multiple packages yourself. Conda
even makes it easy to switch between Python 2 and 3.
⢠In fact, an installation of Anaconda is also the
recommended way to install Jupyter Notebooks.
64. Download and Install Anaconda
1. Go to the Anaconda Website and choose a
Python 3.x graphical installer (A) or a Python 2.x
graphical installer (B).
⢠If you aren't sure which Python version you want to
install, choose Python 3. Do not choose both.
2. Locate your download and double click it.
3. This is an important part of the installation
process.
⢠The recommended approach is, to not check the box
to add Anaconda to your path. This means you will
have to use Anaconda Navigator or the Anaconda
Command Prompt (located in the Start Menu under
"Anaconda")
66. Python modules for machine learning, data
mining and data analytics
⢠Scikit-learn is probably the most useful library for
machine learning in Python. The sklearn library
contains a lot of efficient tools for machine learning
and statistical modeling including classification,
regression, clustering and dimensionality reduction.
⢠scikit-learn is a Python module for machine learning
built on top of SciPy
⢠scikit-learn requires:
⢠Python (>= 3.6)
⢠NumPy (>= 1.13.3)
⢠SciPy (>= 0.19.1)
⢠joblib (>= 0.11)
⢠threadpoolctl (>= 2.0.0)
67. To experiment on data set available with sklearn
https://archive.ics.uci.edu/ml/machine-learning-databases/
⢠Classifying iris flower data set:
⢠The iris dataset is a classification task consisting in
identifying 3 different types of irises (Setosa,
Versicolour, and Virginica) from their petal and sepal
length and width
⢠The data set consists of 50 samples from each of
three species of Iris (Iris setosa, Iris virginica and Iris
versicolor).
⢠Four features were measured from each sample: the
length and the width of the sepals and petals, in
centimeters
68. To experiment on data available with sklearn
from sklearn import datasets
from sklearn import metrics
from sklearn.tree import DecisionTreeClassifier
dataset = datasets.load_iris()
model = DecisionTreeClassifier()
model.fit(dataset.data, dataset.target)
expected = dataset.target #target or class of the data
predicted = model.predict(dataset.data) #predicting for the data with no
target
# for reporting accuracy, Precision, Recall
print(metrics.classification_report(expected, predicted))
# to create confusion matrix
print(metrics.confusion_matrix(expected, predicted))
69. Use all data for training and test with the supplied data
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
music_data = pd.read_csv('music.csvâ)
# to use all data for training
X = music_data.drop(columns=['genre'])
y = music_data['genre']
model = DecisionTreeClassifier() # to create the model
# to train the classifier in all data
model.fit(X,y)
# to test using two instances, age 21 male (1) and age 22 Female (0)
predictions = model.predict([ [21, 1],[22, 0] ])
predictions
70. Divide the dataset into training & test using percentage split
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
music_data = pd.read_csv('music.csvâ)
# to use all data for training
X = music_data.drop(columns=['genre'])
y = music_data['genre']
# to split the data for training & testing using 80:20 perecentage
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
model = DecisionTreeClassifier()
# to train the classifier using 80% train data set
model.fit(X_train,y_train)
# to test using 20% of the test set
predictions = model.predict(X_test)
score = accuracy_score(y_test, predictions)
score
71. Constructing a model
⢠Rather than training always for testing, we can
follow two step;
â First, train and save the model using âjoblibâ
package
â Then use the constructed optimal model for
prediction
72. Training step
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# from sklearn.externals import joblib
import joblib
music_data = pd.read_csv('music.csvâ)
# to use all data for training
X = music_data.drop(columns=['genre'])
y = music_data['genre']
# to split the data for training & testing using 80:20 perecntage
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2)
model = DecisionTreeClassifier() # create model
# train the classifier using 80% train data set
model.fit(X_train,y_train)
# save the model using joblib dump
joblib.dump(model,'decisionTree.modelâ)
73. Prediction and testing step
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
# from sklearn.externals import joblib
import joblib
# load the model using joblib load for testing
joblib.load('decisionTree.model')
# to test using two data set given in array form [age,
gender], 1 represent M & 0 for F
predictions = model.predict([ [21, 1],[22, 0] ])
predictions
74. from sklearn import datasets
#from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn import svm
from sklearn import metrics
dataset = datasets.load_iris()
#print(iris_data)
model = KNeighborsClassifier()
model.fit(dataset.data, dataset.target)
expected = dataset.target
predicted = model.predict(dataset.data)
print(metrics.classification_report(expected, predicted))
# to create confusion matrix
print(metrics.confusion_matrix(expected, predicted))
75. Group Project
⢠Requirement:
âForm a group with at most 2-3 members & use the following
classification algorithms.
⢠Group 1:
âUse: Decision tree, NaĂŻve Bayes & select one more algorithm
⢠Group 2:
âUse: K-Nearest neighbor, Multilayer perceptron & select one more algorithm
⢠Group 3:
âUse: Linear regression, Support vector machine & select one more algorithm
â Each group is expected to compare the performance of classification
algorithms assigned to them using WEKA and Python
â Use data set with at least 500 instances and 10 attributes
â˘Project Report
âWrite a report with the following sections:
⢠Abstract -- ½ page
⢠Introduce problem and objective of the project -- 2 pages
⢠Description of algorithms used for the experiment -- 3 pages
⢠Discussion of experimental result --- 3 pages
⢠Concluding remarks, with major recommendation --- 1 page
⢠Reference (use IEEE referencing style)
⢠Describe, in detail contribution of each member of the group