Thursday 17 November 2022

Angular #1 Installation

Why named it as Angular. b'cos it is written between < > !

 Angular is typescript for building client applications framework.

Angular is easier, clean loosely coupled architecture and more testable and reusable.

Architecture: (FE+BE)

Front End  (UI): Client (Browser) use HTML CSS( Templates) , Type Script (Extended Java Script), angular

Back End  (Data Processing):  Data + API (Application Programming Interface) + Business Logic

Simply, Angular makes life easier!

Angular Version is known as AngularJS. Later versions are known As Angular V x. (latest is Angular 14.0)

Difference between AngularJS and Angular

Architecture :      MVC Model vs  Components and Directives

Language     :      Java Script vs Type Script

Mobile          :    Not Mobile friendly vs Mobile Friendly

Expression Syntax : {{}} vs () []

Dependency Injection : Not used vs Hierarchical DI is used

Routing     :     @routProvider  vs @Route configuration

Code         :      Unmanageable vs Structured


1. First Angular Project:

Download latest stable version node.js from nodejs.org depending on your platform (Windows-32/64/Mac/Linux) (in my case downloaded windows 64 bit node-v18.12.1-x64.msi on 17.11.2022). Install as Administrator. Check  in command prompt by this command

            node --version

Download Angular CLI (Command Line Interface) tool by this command 

            npm install -g @angular/cli

Check in command prompt by this command 

            ng version

Create angular project in command prompt:

            ng new hello-universe  where hello-universe is angular project name.
            Will ask some questions like: 
             Ans 'N' for Would you like to add Angular routing? y/n -
             Select 'CSS' for ? Which stylesheet format would you like to use? 
            will take some time to create necessary files for the angular project

 Download beautiful cross platform code editor: Visual Studio  from https://code.visualstudio.com/download to get VSCodeUserSetup.exe and install as Administrator. 

Go to hello-universe directory. type the following command to check the visual code editor

            code .

 You can observe the Visual studio IDE opened with HELLO-UNIVERSE project. Now our first Angular Project is ready. We can run by this in command prompt 

            ng serve

will build  and display message Compiled successfully at the end.

Now open the browser and type in the address bar

           localhost:4200

Your first application will show screen like this 


Great My friend, You have done it!






        

    


 











Tuesday 12 July 2022

#0 Intro to Data Analysis

 Two Words

Data & Analysis

Data : oil, Electricity,  everywhere, every time, even now.

Analysis : Answer how and Why ?

Analysis :

Data analysis is the process of collecting, modeling, and analyzing data to extract insights that support decision-making. There are several methods and techniques to perform analysis depending on the industry and the aim of the investigation


Why Is Data Analysis Important?

Informed decision-making: 

Reduce costs| Increase Profits

Target Customers Better


DA is a Process

Identify-Collect-Clean-Analyze-Interpret or Infer- Act

(ICCAIA)


Types of DA

1.Descriptive: What ?-Data to Valuable Insights

2.Exploratory: How  ?-To generate Hypothesis to solve specific 3.Problems

4.Diagnostic : Why ? - To tackle and to cure 

5.Predictive  : What if ? - Future Projection

6.Prescriptive : IF-?.Then-This : 


Top DA Methods

1. Cluster Analysis: Similar elements - Grouping Data 

2. Cohort Analysis : Historical data to examine and compare -Google Analytics:

3. Regression Analysis - y=mx+c

4. Factor Analysis : Dimension Reduction

5. Neural Networks : Mimic Human Brain to find solutions

6. Data Mining: Identify patterns, Dependencies, realations, Trends

7. Text Analysis : Actional Insights with Relevant Data

8. TimeSeries Analysis : Data Collected over a specified period of time.

9. Decison Trees: To support smart and strategic Decisions

10. Conjoint Analysis : How individuals value different attributes of a product or Service



Top 17 Data Analysis Techniques:


Collaborate your needs

Establish your questions

Data democratization

Think of data governance 

Clean your data

Set your KPIs

Omit useless data

Build a data management roadmap

Integrate technology

Answer your questions

Visualize your data

Interpretation of data

Consider autonomous technology

Build a narrative

Share the load

Data Analysis tools

Refine your process constantly 


Quality Criteria For Data Analysis 

Internal Validity

External Validity

Reliability

Objectivity



Application of DA:


Academics: Universities and academic institutions can perform data analysis to measure student performance and gather insights on how certain behaviors can further improve education.


Human Resources: Organizations can use data analysis to offer a great experience to their employees and ensure an excellent work environment. They can also utilize the data to find out the best resources whose skill set matches the organizational goals



Communication is very Important


Qualitative


Stephen Few - 8 Types of Quantitative Messages out of DA:

1. Time Series : Line Chart

2. Ranking : Bar Chart

3. Part-to-Whole : Pie Chart

4. Deviation: Bar Comparison : Actual Vs Variation

5. Frequency Distribuition : Histogram

6. Correlation: Scatter Plot 

7. Nominal Comparison : bar Chart

8. Geographical : Cartogram


Quantitative

mean, median, mode, Standard deviation, chi-square, eigen vector



Free software for data analysis


Notable free software for data analysis include:


DevInfo – A database system endorsed by the United Nations Development Group for monitoring and analyzing human development.[149]

ELKI – Data mining framework in Java with data mining oriented visualization functions.

KNIME – The Konstanz Information Miner, a user friendly and comprehensive data analytics framework.

Orange – A visual programming tool featuring interactive data visualization and methods for statistical data analysis, data mining, and machine learning.

Pandas – Python library for data analysis.

PAW – FORTRAN/C data analysis framework developed at CERN.

R – A programming language and software environment for statistical computing and graphics.[150]

ROOT – C++ data analysis framework developed at CERN.

SciPy – Python library for data analysis.

Julia - A programming language well-suited for numerical analysis and computational science.


Thursday 30 June 2022

DATA SCIENCE ETHICS

 DSE definition:

“Data ethics is a new branch of ethics that studies and evaluates moral problems related to data (including generation, recording, curation, processing, dissemination, sharing and use), algorithms (including artificial intelligence, artificial agents, machine learning and robots) and corresponding practices (including responsible innovation, programming, hacking and professional codes), in order to formulate and support morally good solutions (e.g. right conducts or right values).”



MongoDB - Introduction

 MongaDB Features

  • Full cloud-based application data platform.
  • Flexible document schemas.
  • JSON..BSON (BJSON)..
  • Widely supported and code-native data access.
  • Change-friendly design.
  • Powerful querying and analytics.
  • Easy horizontal scale-out with sharding.
  • Simple installation.
  • Cost-effective.

Learning to use MongoDB

Step 1:

Download and install "PyMongo":


                pip install mongadb

Step 2:

                    import pymonga

step 3: list database names

                # import library
import pymongo
# creating a client
myc = pymongo.MongoClient("mongodb://localhost:27017/")
# Just printing existing databases
print(myc.list_database_names()) # ['admin', 'config', 'db1', 'local']

Step 4: Create Collections

# import library
import pymongo
# creating a client
c = pymongo.MongoClient("mongodb://localhost:27017/")
# Just printing existing databases
print(c.list_database_names()) # ['admin', 'config', 'db1', 'local']

# choose any demo db as db1
# create collection customers in db1
db = c['db1']
col = db["customers"]
print(db.list_collection_names())

# add Dict data
dict = { "name": "John", "address": "Highway 37" }
x = col.insert_one(dict)
print(x.inserted_id)

#add Dict1 data
dict2 = { "name": "Peter", "address": "Lowstreet 27" }
y = col.insert_one(dict2)
print(y.inserted_id)

"""
['admin', 'config', 'db1', 'local']
['customers']
62bd57445c7e7af908e87efa
62bd57445c7e7af908e87efb

"""

To display with Object_ID


clist = db.list_collection_names()
if "customers" in clist:
print("The collection exists.")

for x in col.find():
print(x)

"""
['admin', 'config', 'local']
[]
62bd58d899982b27053eb9cc
62bd58d899982b27053eb9cd
The collection exists.
{'_id': ObjectId('62bd58d899982b27053eb9cc'), 'name': 'John', 'address': 'Highway 37'}
{'_id': ObjectId('62bd58d899982b27053eb9cd'), 'name': 'Peter', 'address': 'Lowstreet 27'}
"""

Before and After deleting 

# import library
import pymongo
# creating a client
c = pymongo.MongoClient("mongodb://localhost:27017/")
db = c['db1']
col = db["customers"]
col.drop()
q1 = { 'address': 'Highway 37'}
q2 = { 'address': 'Highway 38'}
q3 = { 'address': 'Highway 39'}

print(10*'-', 'Insering 3 qs')
col.insert_one(q1)
col.insert_one(q2)
col.insert_one(q3)

print(10*'-', 'Before Delete')
for x in col.find():
print(x)

q4 = { 'address': 'Highway 39'}
col.delete_many(q4)
print(10*'-', 'After Delete')
for x in col.find():
print(x)
"""
---------- Insering 3 qs
---------- Before Delete
{'_id': ObjectId('62bd5db330e379663c8851ce'), 'address': 'Highway 37'}
{'_id': ObjectId('62bd5db430e379663c8851cf'), 'address': 'Highway 38'}
{'_id': ObjectId('62bd5db430e379663c8851d0'), 'address': 'Highway 39'}
---------- After Delete
{'_id': ObjectId('62bd5db330e379663c8851ce'), 'address': 'Highway 37'}
{'_id': ObjectId('62bd5db430e379663c8851cf'), 'address': 'Highway 38'}
"""

After deleting another Record

print('After Prinitng')

q5 = { 'address': 'Highway 37'}
col.delete_many(q5)
for x in col.find():
print(x)
"""
After Prinitng
{'_id': ObjectId('62bd5f3cf32b68f5a744b5ab'), 'address': 'Highway 38'}\
"""
Before and After dropping collections
import pymongo
# creating a client
c = pymongo.MongoClient("mongodb://localhost:27017/")
db = c['db1']
col = db["customers"]

many = [
{ "_id": 1, "name": "AMET", "address": "ECR, Chennai"},
{ "_id": 2, "name": "ABS", "address": "Anna Nagar, Chennai"},
]
x = col.insert_many(many)

print('Before dropping')
for x in col.find():
print(x)
col.drop()
print('After dropping')
for x in col.find():
print(x)
"""
Before dropping
{'_id': 1, 'name': 'AMET', 'address': 'ECR, Chennai'}
{'_id': 2, 'name': 'ABS', 'address': 'Anna Nagar, Chennai'}
After dropping

"""

Sorting Collections

import pymongo

# creating a client
c = pymongo.MongoClient("mongodb://localhost:27017/")
db = c['db1']
col = db["customers"]
col.drop()
many = [
{ "_id": 11, "name": "AMET", "address": "ECR, Chennai"},
{ "_id": 21, "name": "ABS", "address": "Anna Nagar, Chennai"},
]
x = col.insert_many(many)
print('Before Sorting')
for x in col.find():
print(x)
doc = col.find().sort("name")

print('After Sorting')
for x in doc:
print(x)

"""
Before Sorting
{'_id': 11, 'name': 'AMET', 'address': 'ECR, Chennai'}
{'_id': 21, 'name': 'ABS', 'address': 'Anna Nagar, Chennai'}
After Sorting
{'_id': 21, 'name': 'ABS', 'address': 'Anna Nagar, Chennai'}
{'_id': 11, 'name': 'AMET', 'address': 'ECR, Chennai'}
"""
Before and After Updating
import pymongo

# creating a client
c = pymongo.MongoClient("mongodb://localhost:27017/")
db = c['db1']
col = db["customers"]
col.drop()
many = [
{ "_id": 11, "name": "AMET", "address": "ECR, Chennai"},
{ "_id": 21, "name": "ABS", "address": "Anna Nagar, Chennai"},
]
x = col.insert_many(many)
q6 = { "address": 'ECR, Chennai' }
newvalues = { "$set": { "address": "#123, East Coast Road, Chennai" } }
print('Before Updation')
for x in col.find():
print(x)
col.update_one(q6, newvalues)
print("After Updation")
#print "customers" after the update:
for x in col.find():
print(x)
"""
Before Updation
{'_id': 11, 'name': 'AMET', 'address': 'ECR, Chennai'}
{'_id': 21, 'name': 'ABS', 'address': 'Anna Nagar, Chennai'}
After Updation
{'_id': 11, 'name': 'AMET', 'address': '#123, East Coast Road, Chennai'}
{'_id': 21, 'name': 'ABS', 'address': 'Anna Nagar, Chennai'}
"""
B4 and After Many Updating using regular expression


import pymongo

client = pymongo.MongoClient("mongodb://localhost:27017/")
db = client["mydatabase"]
col = db["customers"]
col.drop()

many = [
{ "_id": 10, "name": "AMET", "address": "ECR, Chennai"},
{ "_id": 12, "name": "ABS", "address": "Anna Nagar, Chennai"},
{ "_id": 13, "name": "ABS!@", "address": "ECR, Chennai"},
{ "_id": 14, "name": "Stanford", "address": "Anna Nagar, Chennai"},
]
x = col.insert_many(many)


print('Before Updation')
for x in col.find():
print(x)

query = { "address": { "$regex": "^A" } }
newvalues = { "$set": { "name": "AMET Updated" } }
x = col.update_many(query, newvalues)
print(x.modified_count, "documents updated.")

print('After many Updation')
for x in col.find():
print(x)
"""
Before Updation
{'_id': 10, 'name': 'AMET', 'address': 'ECR, Chennai'}
{'_id': 12, 'name': 'ABS', 'address': 'Anna Nagar, Chennai'}
{'_id': 13, 'name': 'ABS!@', 'address': 'ECR, Chennai'}
{'_id': 14, 'name': 'Stanford', 'address': 'Anna Nagar, Chennai'}
2 documents updated.
After many Updation
{'_id': 10, 'name': 'AMET', 'address': 'ECR, Chennai'}
{'_id': 12, 'name': 'AMET Updated', 'address': 'Anna Nagar, Chennai'}
{'_id': 13, 'name': 'ABS!@', 'address': 'ECR, Chennai'}
{'_id': 14, 'name': 'AMET Updated', 'address': 'Anna Nagar, Chennai'}
"""
After using limit to display 
# limit parameter to limit two records
output = col.find().limit(2)
print('After setting Limit(2)')
for x in output:
print(x)
"""
After setting Limit(2)
{'_id': 10, 'name': 'AMET', 'address': 'ECR, Chennai'}
{'_id': 12, 'name': 'AMET Updated', 'address': 'Anna Nagar, Chennai'}
"""

Bon Appetite and Happy MongoDB Coding....Learning!!!



Monday 27 June 2022

Recommendations System - Course for +2 Students

 Recommendation System using pandas and Sklearn

Student Dataset1.csv

id,gender,stream,subject,marks,course,specialization
1,m,science,physics,78,btech,civil
2,f,commerce,maths,56,bsc,maths
3,m,humanities,history,79,ba,history
4,f,commerce,economics,88,bcom,hons
5,m,science,chemistry,79,bsc,biology
6,m,science,maths,98,btech,mech
7,f,commerce,physics,56,bsc,maths
8,m,humanities,history,79,ba,history
9,f,commerce,commerce,76,bcom,hons
10,m,science,physics,89,bsc,biology

Code snippet (Thanks to  Siddharth Sachdeva — August 25, 2021, Analytics Vidya)

#S1 importing necessary libraries.
import pandas as pd
data = pd.read_csv(
r"dataset1.csv")
#s2
descriptions =data['gender'] +' '+ data['subject'] + ' ' + data['stream'] +' '+ data['marks'].apply(str)
#Printing the first description
print(descriptions[0])
# s3 similarity matrix
#import sklearn.TfidfVector
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import linear_kernel
def create_similarity_matrix(new_description, overall_descriptions):
overall_descriptions.append(new_description)
# Define a tfidf [Term Frequency Inverse document frequency] vectorizer and remove all stopwords.
tfidf = TfidfVectorizer(stop_words="english")
tfidf_matrix = tfidf.fit_transform(overall_descriptions)
tfidf_matrix.shape
cosine_sim = linear_kernel(tfidf_matrix
,tfidf_matrix)
return cosine_sim
#s5 Sim Matrix reco
def get_recommendations(new_description,overall_descriptions):

cosine_sim = create_similarity_matrix(new_description
,overall_descriptions)
sim_scores =
list(enumerate(cosine_sim[-1]))
sim_scores =
sorted(sim_scores,key =lambda x:x[1],reverse= True )
sim_scores = sim_scores[
1:10]
indices = [i[
0]for i in sim_scores]
return data.iloc[indices]
# s6 Recommendations
new_description = pd.Series('m physics science 78')
recommendation= get_recommendations(new_description
,descriptions)
print(recommendation[0:3])
"""
id gender stream subject marks course specialization 0 1 m science physics 78 btech civil 6 7 f commerce physics 56 bsc maths 4 5 m science chemistry 79 bsc biology
"""

Simple not refined. But throw some light on basics of Recommendation System.

Sunday 26 June 2022

P#32 Reg expression

To find a pattern in a statement

match = re.search('love', 'i love you all')

if match:
print('found love')
else:
print('love Not found')

# found love
match = re.search('love', 'i leave you all')

if match:
print('found love')
else:
print('love Not found')

# love Not found

 ## . = any char but \n
match = re.search(r'..ve', 'i love you all') # found,
print(match)

To match email

 to check up Google Account
str = 'hello I am so& so i have account you@google.com'
match = re.search(r'\w+@\w+', str)
if match:
print(match.group()) #you@google

match = re.search(r'[\w.-]+@[\w.-]+', str)
if match:
print(match.group()) ## 'you@google.com'

To Validate IFSC code in banks

import re
def isValidIFSCode(str):
# Regex to check valid IFSC Code.
regex = "^[A-Z]{4}0[A-Z0-9]{6}$" # 4 Alphabets,0,
# Compile the ReGex
p = re.compile(regex)
# If the string is empty
# return false
if (str == None):
return False
# Return if the string
# matched the ReGex
if (re.search(p, str)):
return True
else:
return False
# Driver code
# Test Case 1:
str1 = "SBIN0125620"
print(isValidIFSCode(str1))

# Test Case 2:
str2 = "SBIN0125"
print(isValidIFSCode(str2))

# Test Case 3:
str3 = "1234SBIN012"
print(isValidIFSCode(str3))

# Test Case 4:
str4 = "SBIN7125620"
print(isValidIFSCode(str4))

# This code is contributed by avanitrachhadiya2155

"""
True
False
False
False
"""

Please Note:


# regex = "^[A-Z]{4}0[A-Z0-9]{6}$";
# Where:
# ^ represents the starting of the string.
# [A-Z]{4} represents the first four characters should be upper case alphabets.
# 0 represents the fifth character should be 0.
# [A-Z0-9]{6} represents the next six characters usually numeric, but can also be alphabetic.
# $ represents the ending of the string.

To test Pin Code

import re

def isValidPinCode(pinCode):
# Regex to check valid pin code
# of India.
regex = "^[1-9]{1}[0-9]{2}\\s{0,1}[0-9]{3}$";

# Compile the ReGex
p = re.compile(regex);

# If the pin code is empty
# return false
if (pinCode == ''):
return False;

# Pattern class contains matcher() method
# to find matching between given pin code
# and regular expression.
m = re.match(p, pinCode);

# Return True if the pin code
# matched the ReGex else False
if m is None:
return False
else:
return True



# check Driver code
if __name__ == "__main__":
# Test case 1
num1 = "625001";
print(num1, ": ", isValidPinCode(num1));

# Test case 2:
num2 = "625 001";
print(num2, ": ", isValidPinCode(num2));

# Test case 3:
num3 = "0625 001";
print(num3, ": ", isValidPinCode(num3));

# Test case 4:
num4 = "6250001";
print(num4, ": ", isValidPinCode(num4));

Result


"""
625001 : True
625 001 : True
0625 001 : False
6250001 : False
"""

To check PANCARD in India


# To Valiate pan Card

import re

def checkPanCard():
import re


def isValidPanCardNo(panCardNo):

# PAN Card number
regex = "[A-Z]{5}[0-9]{4}[A-Z]{1}"

# Compile the ReGex
p = re.compile(regex)

# If the PAN Card number
# is empty return false
if(panCardNo == None):
return False

# Return if the PAN Card number
# matched the ReGex
if(re.search(p, panCardNo) and
len(panCardNo) == 10):
return True
else:
return False

# Driver Code.


# Test Case 1:
str1 = "AFGHA2318J"
print(isValidPanCardNo(str1),' ',str1)

# Test Case 2:
str2 = "23AFGHN18J"
print(isValidPanCardNo(str2),str2)

# Test Case 3:
str3 = "AFGHA2318JM"
print(isValidPanCardNo(str3),str3)

# Test Case 4:
str4 = "AFGHA23184"
print(isValidPanCardNo(str4),str4)

# Test Case 5:
str5 = "AFGHA 23184"
print(isValidPanCardNo(str5),str5)

checkPanCard()
"""
True AFGHA2318J
False 23AFGHN18J
False AFGHA2318JM
False AFGHA23184
False AFGHA 23184
"""


Making Prompts for Profile Web Site

  Prompt: Can you create prompt to craft better draft in a given topic. Response: Sure! Could you please specify the topic for which you...