---
title: "NMP Code"
author: "Sahil Mapkar"
date: "2024-03-19"
output: word_document
---
## NMP Code
```
>library(umap)
>library(ggplot2)
>library(factoextra)
>library("writexl")
```
*Import functions for data and graphing*
*(umap) = R studio package UMAP (Version 0.2.10.0) - for dimensional reduction*
(*ggplot2) = R studio package ggplot2 (version 3.3. 4) - for plotting*
*(factoextra) = R studio package factoextra (Version 1.0.7) - for clustering*
*("writexl") = R studio package UMAP (Version 1.5.0) - for excel exporting*
```
>Reduced_file_name <-file name
```
*Imported file name on the right and reduce file name on left*
```
>Name_data <-reduced file name[ ,columns]
```
*On the right put reduced file name and in brackets leave space empty for rows and after comma choose columns from file that will be used as 4 parameters. On left name data.*
```
>Name_scale <-scale(Name_data)
```
*Scale the data set.*
```
>umap_result <-umap(Name_scale, n_neighbors= #, n_components = #)
```
*Apply dimension reduction. Neighbors \# is traditionally set to 20. Components \# sets dimensionality. Component of 1 determines scores.*
```
>df_con <-data.frame(umap_result[["layout"]])
```
*Frame all the data created by the UMAP function into an exportable format.*
```
>x <-df_con[ ,1]
>y <-df_con [ ,2]
>x <-unlist(x)
>y <-unlist(y)ggplot(df_con, aes(x=x, y=y))+ geom_point()
```
*Parse out data points then plot for raw UMAP.*
```
>km.res <-kmeans(T_scale, #, nstart = #)
>fviz_cluster(km.res, df_con, frame = FALSE, geom = "point")
NMP Code.docx
```
*Apply clustering. \# determines number of clusters. nStart \# is traditionally set to 5.*
```
>km <-unlist(km.res)
>km.matrix <-as.matrix(km)
>km.df <-data.frame(km.matrix)
```
*Frame clustering data into an exportable format.*
```
>write_xlsx(km.df, "C:Users/Desktop\
FILE_NAME.xlsx")
>write_xlsx(df_con, "C:Users/Desktop\
FILE_NAME.xlsx")
```
*Export data into an exportable excel.*