October 2018
Intermediate to advanced
172 pages
4h 6m
English
The first step is to convert the labels generated by an unsupervised machine learning algorithm, such as the k-means algorithm, and append it to the dataset. We can do this by using the following code:
#Reading in the datasetdf = pd.read_csv('fraud_prediction.csv')#Dropping the target feature & the indexdf = df.drop(['Unnamed: 0', 'isFraud'], axis = 1)
In the preceding code, we read in the fraud detection dataset and drop the target and index columns:
#Initializing K-means with 2 clustersk_means = KMeans(n_clusters = 2)#Fitting the model on the datak_means.fit(df)
Next, in the preceding code we initialize and fit a k-means model with two clusters:
#Extracting labels target_labels = k_means.predict(df)#Converting ...
Read now
Unlock full access