How to use find_cls method in autotest

Best Python code snippet using autotest_python

Mall Customer Segmentation Data.py

Source:Mall Customer Segmentation Data.py Github

copy

Full Screen

1#!/usr/bin/env python2# coding: utf-83# In[3]:4## For data manupilation5import numpy as np6import pandas as pd7# For os8import os9# remove warning10import warnings11warnings.filterwarnings("ignore")12# In[4]:13os.chdir("D:\\data analyst data\\download data\\Mall Customer Segmentation Data")14os.listdir()15# In[5]:16df = pd.read_csv('Mall_Customers.csv')17df.head() 18# In[6]:19df.isnull().sum() # checking if there is any null value 20# In[7]:21df.rename(columns= {'Annual Income (k$)' : 'Annual_Income', 'Spending Score (1-100)' : 'Spending_Score'}, inplace = True)22# In[8]:23df.drop('CustomerID', axis = 1 ,inplace = True)24# In[9]:25df.dtypes # checking data type 26# In[10]:27df.shape #checking shape of data 28# In[11]:29df.columns.values #checking columns 30# In[12]:31# For creating colormaps32import matplotlib.pyplot as plt33import seaborn as sns34# for clustering 35from sklearn.cluster import KMeans36import time # Measuring process time37from sklearn.preprocessing import StandardScaler # For data processing38from sklearn.model_selection import train_test_split39from sklearn.tree import DecisionTreeClassifier as dt40# In[13]:41np.min(df.Age), np.max(df.Age)42# In[14]:43sns.distplot(df.Age) # diagrams 44# In[15]:45sns.distplot(df.Annual_Income, hue = 'Gender')46# In[ ]:47sns.distplot(df.Spending_Score)48# In[16]:49sns.jointplot(df.Age, df.Spending_Score)50# In[17]:51sns.jointplot(df.Annual_Income, df.Age , kind="kde")52# In[18]:53sns.jointplot(df.Annual_Income, df.Age , kind="hex")54# In[19]:55sns.jointplot(df.Annual_Income, df.Age , kind="reg")56# In[20]:57cust_group = df.groupby(['Gender','Age']).sum().reset_index()58cust_group59# In[21]:60df['Annual_Income'].min()61# In[22]:62df['Annual_Income'].max()63# In[23]:64df['Annual_Income_cat'] = pd.cut(65 df['Annual_Income'],66 bins = 3,67 labels= ['low', 'medium','high']68 )69df70# In[24]:71plt.figure(1 , figsize = (10 , 10))72sns.barplot(x = 'Annual_Income_cat', y = 'Age',hue = 'Gender', data = df, )73# In[25]:74plt.figure(figsize=(15,3))75sns.barplot(data=cust_group,x='Age',y='Spending_Score',hue='Gender')76# In[26]:77sns.pairplot(data=cust_group, hue='Gender')78# In[27]:79df.drop(columns=['Annual_Income_cat'],inplace= True) #Dropping columns not needed80# In[28]:81df82# In[29]:83from sklearn.preprocessing import LabelEncoder as le84enc=le()85# In[31]:86df['Gender']=enc.fit_transform(df['Gender'])87df.head()88# In[32]:89find_cls=[]90for i in range(1,15):91 kmean = KMeans(n_clusters=i)92 kmean.fit(df)93 find_cls.append(kmean.inertia_)94# In[33]:95find_cls96# In[34]:97fig, axs = plt.subplots(figsize=(12,5))98sns.lineplot(range(1,15),find_cls, ax=axs,marker='X')99axs.axvline(5, ls="--", c="crimson") # CRIMSON is color, ls - line style100axs.axvline(6, ls="--", c="crimson")101plt.grid() # square lines in back ground102plt.show103# In[35]:104kmean=KMeans(n_clusters=5) # we found that best clusters are 5105kmean.fit(df)106# In[36]:107kmean.inertia_108# In[37]:109kmean.cluster_centers_110# In[38]:111clust_centers=kmean.cluster_centers_112# In[39]:113df.head()114# In[40]:115kmean.labels_116# In[41]:117df['center_cluster']=kmean.labels_118# In[42]:119df120# In[47]:121fig,(ax1,ax2)=plt.subplots(nrows=1, ncols=2,figsize=(15,5))122sns.scatterplot(data = df, x = 'Age', y = 'Spending_Score', ax=ax1, hue = 'center_cluster',palette='Set1') # good color use palette =1123sns.scatterplot(data = df, x='Annual_Income', y ='Spending_Score', ax=ax2, hue='center_cluster',palette='Set1')124# In[344]:125fig,(ax1,ax2)=plt.subplots(nrows=1, ncols=2,figsize=(15,5))126ax1.scatter(kmean.cluster_centers_[:,1], kmean.cluster_centers_[:,3],marker='X',color='red') 127ax2.scatter(kmean.cluster_centers_[:,2], kmean.cluster_centers_[:,3],marker='X',color='red')128# In[ ]:129# In[178]:130# Copy 'Age' column to another variable and then drop it131# We will not use it in clustering132y = df['Age'].values133df.drop(columns = ['Age'], inplace = True)134# In[179]:135y...

Full Screen

Full Screen

student_module.py

Source:student_module.py Github

copy

Full Screen

...35 def cal_result(self):36 self.total = self.java + self.php + self.python + self.nodejs37 self.percentage = self.total / 438 # find class39 def find_cls(self):40 if self.java < 35 or self.php < 35 or self.python < 35 or self.nodejs < 35:41 self.cls = "Fail"42 elif self.percentage >= 70:43 self.cls = "Distinction"44 elif self.percentage >= 60:45 self.cls = "1st Class"46 elif self.percentage >= 50:47 self.cls = "2nd Class"48 elif self.percentage >= 40:49 self.cls = "3rd Class"50 else:51 self.cls = "Pass Class"52# main method53if __name__ == "__main__":54 obj = Student()55 obj.get_stud(1, "hitesh", "malegaon", 54, 54, 35, 65)56 obj.cal_result()57 obj.find_cls()58 obj.display_stud()59 # objs = [Student() for i in range(3)]60 # for obj in objs:61 # obj.get_Student()62 # for obj in objs:63 # obj.cal_result()64 # obj.find_cls()...

Full Screen

Full Screen

1_6_classes_childes_1.py

Source:1_6_classes_childes_1.py Github

copy

Full Screen

...4# <имя класса 1> : <имя класса 2> <имя класса 3> ... <имя класса k>5# Это означает, что класс 1 отнаследован от класса 2, класса 3, и т. д.6# словарь наследник : предки7child_parents_dict = {}8def find_cls(a, b):9 if a == b:10 return True11 elif a in child_parents_dict[b]:12 return True13 else:14 for c in child_parents_dict[b]:15 if find_cls(a, c):16 return True17 return False18for i in range(int(input())):19 inp = str(input()).split()20 child_parents_dict.update({inp[0]: set(inp[2:])})21for i in range(int(input())):22 inp = (str(input()).split())23 cls1, cls2 = inp[0], inp[1]24 if find_cls(cls1, cls2):25 print("Yes")26 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful