0% found this document useful (0 votes)
48 views11 pages

Innovative Assignment PDF

The document is an innovative assignment on predictive maintenance of milling machines submitted by Mazin Vora for the Introduction to AI & ML course. It includes Python code for data analysis using pandas and scikit-learn, detailing the structure and unique values of a dataset with 10,000 entries related to machine performance. The assignment aims to explore predictive maintenance techniques through data analysis and machine learning.

Uploaded by

Mazin Vora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views11 pages

Innovative Assignment PDF

The document is an innovative assignment on predictive maintenance of milling machines submitted by Mazin Vora for the Introduction to AI & ML course. It includes Python code for data analysis using pandas and scikit-learn, detailing the structure and unique values of a dataset with 10,000 entries related to machine performance. The assignment aims to explore predictive maintenance techniques through data analysis and machine learning.

Uploaded by

Mazin Vora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

4/17/24, 10:31 PM Innovative Assignment

INNOVATIVE ASSIGNMENT OF INTRODUCTION TO AI & ML

COURSE CODE: 1CS501 SUBMITTED TO: DR.SHEBAZ MEMON DATE: 13 APRIL 2024

PREDICTIVE MAINTENANCE OF MILLING MACHINE

ROLL NO.: 23BME053 NAME: MAZIN VORA BRANCH: MECHANICAL ENGINEERING (P3)

In [2]: import pandas as pd


import numpy as np
import matplotlib as plt
from sklearn.metrics import accuracy_score, classification_report
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split

C:\Users\mazin\AppData\Local\Temp\ipykernel_18852\80409913.py:1: DeprecationWarni
ng:
Pyarrow will become a required dependency of pandas in the next major release of
pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better i
nteroperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466

import pandas as pd

In [3]: df=pd.read_csv("Dataset.csv", header = 'infer')


df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10000 entries, 0 to 9999
Data columns (total 9 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 UDI 10000 non-null int64
1 Product ID 10000 non-null object
2 Type 10000 non-null object
3 Air temperature [K] 10000 non-null float64
4 Process temperature [K] 10000 non-null float64
5 Rotational speed [rpm] 10000 non-null int64
6 Torque [Nm] 9994 non-null float64
7 Tool wear [min] 9994 non-null float64
8 Failure Type 10000 non-null int64
dtypes: float64(4), int64(3), object(2)
memory usage: 703.3+ KB

UNIQUE VALUE COUNT AND UNIQUE VALUES IN DATA

In [4]: for column in df.columns:


unique_counts = df[column].value_counts()
unique_values = df[column].unique()

localhost:8888/doc/tree/Innovative Assignment.ipynb 1/11


4/17/24, 10:31 PM Innovative Assignment

print(f"Unique value counts for column '{column}':\n{unique_counts}")


print(f"\nUnique values for column '{column}':\n{unique_values}\n{'='*50}\n"

localhost:8888/doc/tree/Innovative Assignment.ipynb 2/11


4/17/24, 10:31 PM Innovative Assignment

Unique value counts for column 'UDI':


UDI
1 1
6671 1
6664 1
6665 1
6666 1
..
3334 1
3335 1
3336 1
3337 1
10000 1
Name: count, Length: 10000, dtype: int64

Unique values for column 'UDI':


[ 1 2 3 ... 9998 9999 10000]
==================================================

Unique value counts for column 'Product ID':


Product ID
M14860 1
L53850 1
L53843 1
L53844 1
L53845 1
..
M18193 1
M18194 1
L50515 1
L50516 1
M24859 1
Name: count, Length: 10000, dtype: int64

Unique values for column 'Product ID':


['M14860' 'L47181' 'L47182' ... 'M24857' 'H39412' 'M24859']
==================================================

Unique value counts for column 'Type':


Type
L 6000
M 2997
H 1003
Name: count, dtype: int64

Unique values for column 'Type':


['M' 'L' 'H']
==================================================

Unique value counts for column 'Air temperature [K]':


Air temperature [K]
300.7 279
298.9 231
297.4 230
300.5 229
298.8 227
...
304.4 7
296.0 6
295.4 3

localhost:8888/doc/tree/Innovative Assignment.ipynb 3/11


4/17/24, 10:31 PM Innovative Assignment

295.3 3
304.5 1
Name: count, Length: 93, dtype: int64

Unique values for column 'Air temperature [K]':


[298.1 298.2 298.3 298.5 298.4 298.6 298.7 298.8 298.9 299. 299.1 298.
297.9 297.8 297.7 297.6 297.5 297.4 297.3 297.2 297.1 297. 296.9 296.8
296.7 296.6 296.5 296.3 296.4 296.2 296.1 296. 295.9 295.8 295.7 295.6
295.5 295.4 295.3 299.2 299.3 299.5 299.4 299.6 299.7 299.8 299.9 300.
300.1 300.2 300.3 300.4 300.5 300.6 300.7 300.8 300.9 301. 301.1 301.2
301.3 301.4 301.5 301.6 301.7 301.8 301.9 302. 302.1 302.2 302.3 302.4
302.5 302.6 302.7 302.8 302.9 303. 303.1 303.2 303.3 303.4 303.5 303.6
303.7 303.8 303.9 304. 304.1 304.2 304.3 304.4 304.5]
==================================================

Unique value counts for column 'Process temperature [K]':


Process temperature [K]
310.6 317
310.8 273
310.7 266
308.6 265
310.5 263
...
306.9 4
313.7 4
305.8 3
305.7 2
313.8 2
Name: count, Length: 82, dtype: int64

Unique values for column 'Process temperature [K]':


[308.6 308.7 308.5 309. 308.9 309.1 309.2 309.3 309.4 309.5 308.8 308.4
308.3 308.2 308.1 308. 307.9 309.6 309.7 309.8 309.9 310. 310.1 310.2
307.8 307.7 307.6 307.5 307.4 307.3 307.2 307.1 307. 306.9 306.8 306.7
306.6 306.5 306.4 306.3 306.2 306.1 306. 305.9 305.8 305.7 310.3 310.4
310.5 310.6 310.7 310.8 310.9 311. 311.1 311.2 311.3 311.4 311.5 311.6
311.7 311.8 311.9 312. 312.1 312.2 312.3 312.4 312.5 312.6 312.7 312.8
313. 313.1 312.9 313.2 313.3 313.4 313.5 313.6 313.8 313.7]
==================================================

Unique value counts for column 'Rotational speed [rpm]':


Rotational speed [rpm]
1452 48
1435 43
1447 42
1429 40
1469 40
..
2197 1
2211 1
1905 1
1893 1
2450 1
Name: count, Length: 941, dtype: int64

Unique values for column 'Rotational speed [rpm]':


[1551 1408 1498 1433 1425 1558 1527 1667 1741 1782 1423 1339 1742 2035
1542 1311 1410 1306 1632 1375 1450 1581 1758 1561 1861 1512 1811 1439
1693 1798 1419 1665 1559 1452 1379 1350 1362 1368 1372 1472 1489 1843
1418 1412 2861 1383 1497 1565 1691 1477 1513 1661 1378 1393 1592 1829

localhost:8888/doc/tree/Innovative Assignment.ipynb 4/11


4/17/24, 10:31 PM Innovative Assignment

1812 1523 1394 1679 1466 1924 1369 1601 1461 1455 1398 1402 1445 1453
1469 1422 1804 1436 1544 1487 1753 1830 1727 1622 1351 1575 1750 1529
1852 1991 1555 1441 1591 1621 1572 1872 1499 1486 1680 1431 1564 1599
1707 1467 1310 1546 1560 1329 1413 1587 1473 1737 1430 1711 1420 1297
1449 1268 1511 1778 1407 1391 1612 1515 1463 1584 1850 1528 1987 1495
1478 1471 1282 1586 1468 1440 1733 1458 1318 1610 1462 1382 1618 1988
1304 1475 1824 1342 1485 1446 1301 1606 1539 1666 1678 2678 1432 1588
1609 1636 1490 1344 1421 1386 1589 1548 1664 1447 1434 1416 1827 1569
1629 1538 1570 1424 1552 1611 1777 1348 1442 1395 1627 1585 1405 1662
1620 1357 1514 1331 1615 1482 1522 1654 1736 1390 1454 1954 1800 1524
1520 1484 1426 1652 1401 1479 1819 1456 1626 2051 1568 1805 1385 1438
1335 1392 1716 1713 2129 1567 1740 1374 1579 1305 1526 1313 1300 1646
1714 1685 1550 1518 1448 1488 1699 1501 1373 1703 1720 1647 1749 1995
1563 1474 1530 1388 2448 1459 1617 1595 1400 1507 1674 1658 1623 1517
1521 1596 1640 1353 1604 1533 1754 2564 1842 1712 1414 1319 1249 1460
1491 1571 1774 1502 2100 1722 1273 1600 1429 1573 2151 1657 1333 1496
1208 1848 1493 1504 1341 1535 1389 1399 1582 1793 1376 1643 1510 1276
1476 2874 2182 1619 1380 1833 1323 1583 1556 1324 1347 1404 1470 1326
1505 1464 1543 1893 1415 1428 1715 1732 2027 1553 1709 1549 1443 1675
1365 1759 1516 1775 1296 1803 1831 1958 1809 1332 1437 1698 1274 1650
1503 1574 1669 1541 1935 1676 1700 1697 2001 1628 1525 1668 1312 1278
1330 1480 1616 1547 2194 2000 1336 1403 1534 1634 1642 1686 1725 1926
1509 1545 1554 1858 1536 1226 1608 2015 1683 1435 1562 1427 1729 1738
1822 1577 1295 1656 1874 1531 1735 1354 1815 1838 1696 1500 1557 1506
1361 1451 1289 1356 1978 1483 1492 1537 1286 1337 1343 1580 1409 1743
1641 1605 2010 1828 1882 1285 1867 1338 1481 1566 1631 1465 1406 2833
1444 1898 1951 1645 2044 1594 1358 1325 1892 1915 1235 1739 1397 2161
1651 1370 1256 2270 1593 1396 1949 1363 1597 1263 1823 1287 1911 1387
1508 1532 1644 1917 1655 1748 1638 2119 1168 2071 1633 1637 1291 1881
1760 1648 1684 1607 1671 1927 1718 1840 1345 1653 1731 2008 2721 1695
1540 1734 1292 1790 2077 1340 1258 1706 1672 1690 1271 1635 1846 1834
1316 1367 1355 1352 1578 1417 1794 1776 1979 1371 2540 1359 1694 1702
1763 1880 1364 2440 1726 1309 1280 1885 2243 2153 1868 1322 2098 1929
1243 1411 1814 1719 1663 1771 1613 1721 1328 1717 1598 1334 1681 1708
1366 1786 1603 2737 1494 1944 2083 1320 1377 1602 1677 1315 1519 1692
2056 1976 1723 2206 2101 1614 2449 1787 1757 2304 1349 1781 2216 2090
1230 2057 1639 1688 1877 1802 1590 1844 1921 1303 1761 1769 1384 1792
1764 1952 2029 1457 1906 1948 1260 1624 2381 1576 1942 1950 1981 2886
1847 2567 1767 2066 1784 1859 1327 1855 1752 1630 1242 1705 1902 1968
1687 1977 1314 1969 1704 1791 1839 1266 1308 1281 1202 1298 1747 1785
1279 1381 1660 1360 1940 1321 1701 2280 1941 1863 1762 1908 1939 1816
1245 1965 2549 1821 1746 1886 1755 1744 1841 1772 1845 1856 1689 2384
2022 1267 2329 1946 2069 1730 1766 1972 1795 1293 2248 2250 1957 2421
1207 1670 1283 1346 1254 1294 1779 1751 2256 1728 1625 1869 2266 1302
1851 1299 1889 1925 2183 1887 1875 1807 1997 1682 2496 1251 1888 1255
1810 2355 1996 2007 1290 1659 1934 2174 1783 1932 2293 2141 2563 1780
1649 2179 2025 1724 1288 1984 2068 1269 1937 1217 2289 1962 2432 1673
2760 1989 2012 2297 1918 2639 1270 2092 1871 1980 1899 1317 1799 2672
1192 1947 2465 1866 1928 1873 1916 1891 1227 2034 2709 1773 1903 2041
1953 1985 1909 1931 2143 2691 2305 1865 2197 1895 1884 1765 1212 1832
2211 1710 2157 2203 1905 1284 2032 2372 2825 2695 1259 2009 2676 2224
2016 1923 1967 1307 1900 1275 2102 1820 1238 1854 1879 1817 1222 1959
2133 2663 1818 2268 1756 1806 1922 2168 2232 1919 2344 1768 1789 2497
2659 1825 2113 2245 1883 2643 2028 1901 2354 2117 1897 2130 2116 2706
1262 2030 2024 1826 2023 2052 1745 1257 2370 2080 2170 1265 1907 2323
2076 2055 1234 1894 1920 2156 1853 2003 2235 2047 1813 1228 2089 1236
1975 1910 2165 2204 2021 1233 1248 1994 2065 1183 1913 2595 1770 1961
1966 2103 1876 2093 1998 2137 2219 2636 1836 2207 2237 1801 2073 1878
2377 2437 2478 2633 2127 2006 1960 2514 2288 1788 1261 2158 2424 1808
1983 2084 1864 2261 1999 2579 2013 2074 2026 1936 1246 2097 1964 2072

localhost:8888/doc/tree/Innovative Assignment.ipynb 5/11


4/17/24, 10:31 PM Innovative Assignment

1272 1200 2218 2142 2140 1264 2710 2004 1835 2144 1229 1796 2099 2240
1225 2617 1971 1181 1870 2011 2262 2267 2188 1797 1896 2358 1970 2456
2042 1904 1862 2186 2033 2189 1837 2136 1890 2109 2049 2053 2231 2271
2118 2312 2450]
==================================================

Unique value counts for column 'Torque [Nm]':


Torque [Nm]
40.2 52
38.5 50
35.8 50
42.4 50
37.7 49
..
12.0 1
8.0 1
62.6 1
16.4 1
15.5 1
Name: count, Length: 577, dtype: int64

Unique values for column 'Torque [Nm]':


[42.8 46.3 49.4 39.5 40. 41.9 42.4 40.2 28.6 28. nan 44.3 51.1 30.
19.6 48.4 46.6 45.6 54.5 32.5 42.7 44.8 30.7 25.7 37.3 23.3 39. 24.6
44.2 30.1 48.2 25.5 48.3 34.7 48.6 36.7 39.2 50.7 52.5 45.4 50.8 49.1
48.5 47.5 25.8 53.9 44.1 4.6 54.9 43.8 35.1 40.7 40.3 29.5 54.4 52.6
38.2 22.9 25.9 38.6 45.1 28.7 32.4 65.7 22.6 45.5 44.4 35. 32.3 46.7
47.9 41.3 51.5 37.9 49.9 40.8 40.1 47.6 26.8 43.9 31.8 45.2 24.9 27.1
43. 31.9 52.2 35.3 29.9 32.7 25. 20.7 40.6 40.5 43.4 31.1 46.8 34.1
22.5 43.5 29.4 45.7 33. 28.1 44.7 41.2 32.2 60.5 46.5 34.3 41.1 27.7
43.2 49.6 53. 28.5 55.3 55.8 36.1 35.2 28.2 50.5 33.6 48. 39.9 37.6
41. 27. 36.2 19.8 46. 47. 60.7 52.3 35.5 43.6 26. 32.6 42.9 62.3
59.1 20.8 33.7 58.3 21.4 50.2 49.8 24.2 48.1 30.6 56. 43.1 34.6 51.8
10.7 49.5 40.9 47.1 35.7 32.8 44. 33.9 52.9 44.9 37.1 38.3 31.6 46.2
52.7 24.3 45. 34.4 29.3 53.8 49.2 34.8 34.9 38.7 36.6 50.3 51.6 58.8
31.4 33.5 56.8 56.2 42.6 35.8 40.4 63. 63.9 32.1 43.7 21.1 24.8 37.
39.6 54.7 26.6 23.4 36.5 19.2 36. 33.2 42.2 25.3 18.7 35.6 27.5 47.2
41.8 28.4 27.8 41.4 56.7 51.9 31.3 20.5 39.4 13.8 32.9 31.7 31. 36.9
48.9 34.2 36.8 30.9 47.8 55.2 57.5 37.2 38.1 51.7 42. 37.4 12.8 50.9
60.4 54.8 37.7 28.9 49.7 16.9 30.4 59.8 45.9 57.6 42.1 34.5 37.8 50.1
17.7 39.7 23.7 36.3 38.5 61.5 26.7 59.9 41.7 46.1 57.4 53.6 42.3 4.2
41.5 16.5 57.3 32. 56.9 35.9 38.8 30.2 27.4 43.3 37.5 58.2 20.6 35.4
50.6 29.8 33.4 52.4 24.7 22.1 39.3 53.2 54.3 45.3 29. 49. 55.4 33.1
27.9 50.4 53.1 16.8 21.3 71.6 33.8 47.7 29.1 57.8 41.6 23.9 51.3 58.7
28.8 38.9 44.5 20.1 58.6 47.4 24. 25.4 61.2 47.3 48.8 24.4 29.7 26.4
55.6 50. 27.3 46.4 45.8 58.1 23.8 44.6 54.6 46.9 62. 22.3 48.7 56.5
51. 30.8 33.3 18.9 52.1 22.8 52. 5.6 22.7 53.3 21.7 22.4 76.2 42.5
31.2 14.6 27.6 21.9 61.8 20.9 26.2 21. 39.1 18.3 63.4 19.4 29.6 53.4
68.3 57.7 34. 38. 19.1 25.1 52.8 30.5 36.4 25.2 39.8 56.4 17.5 9.3
69. 51.4 61.4 69.1 25.6 58. 57.1 30.3 20.4 55.9 53.5 13.3 59. 23.5
14. 15.7 65.9 15.3 57. 74.5 27.2 31.5 26.1 8.8 62.7 18.2 54. 49.3
29.2 61.9 28.3 60.2 19.3 58.5 69.4 16.3 17.4 55.7 15.1 55.5 19. 59.6
18. 61. 51.2 62.9 59.5 57.9 59.3 26.3 21.6 19.9 54.2 14.2 60.1 20.3
23.2 3.8 67.3 23.6 56.3 23. 62.8 21.5 58.4 54.1 20.2 57.2 55.1 18.4
67. 59.7 66.3 60. 15.4 38.4 60.3 64. 13. 60.6 56.1 60.9 55. 15.
20. 63.6 68.2 26.5 53.7 16.6 67.5 66.5 62.1 61.3 15.9 64.8 65.1 17.8
62.2 63.2 13.5 14.4 19.7 24.5 72.8 21.8 22. 17.9 63.1 62.4 56.6 16.4
62.6 8. 65.3 15.8 12. 18.6 11.8 68.9 13.7 23.1 26.9 67.6 9.7 62.5
18.8 66.7 59.2 17.3 12.1 16.1 68.6 59.4 68. 13.9 5.8 12.6 65.5 66.8
10.8 17.2 21.2 16. 67.8 17. 11.4 58.9 70.6 15.2 17.6 61.1 12.7 64.4

localhost:8888/doc/tree/Innovative Assignment.ipynb 6/11


4/17/24, 10:31 PM Innovative Assignment

18.1 16.7 9.8 63.8 70.5 68.5 71.3 14.7 70. 18.5 66.4 67.9 64.6 64.9
24.1 66.1 73.6 63.7 60.8 65.8 65.6 12.2 63.5 67.2 22.2 14.3 13.4 64.7
61.7 14.5 69.6 14.9 12.5 65.2 71.8 76.6 64.2 69.7 61.6 64.1 72. 75.4
15.6 19.5 16.2 15.5]
==================================================

Unique value counts for column 'Tool wear [min]':


Tool wear [min]
0.0 120
2.0 69
5.0 63
7.0 58
59.0 58
...
237.0 1
239.0 1
241.0 1
251.0 1
253.0 1
Name: count, Length: 246, dtype: int64

Unique values for column 'Tool wear [min]':


[ 0. 3. 5. 7. nan 11. 14. 16. 18. 21. 24. 29. 34. 37.
40. 42. 44. 47. 50. 55. 58. 63. 65. 68. 70. 73. 75. 77.
82. 84. 86. 89. 91. 93. 95. 98. 101. 104. 106. 111. 113. 115.
117. 120. 125. 128. 130. 133. 135. 140. 143. 145. 147. 152. 154. 156.
158. 160. 162. 165. 167. 169. 172. 174. 177. 179. 181. 184. 189. 191.
193. 196. 198. 200. 202. 204. 206. 208. 2. 4. 9. 13. 15. 17.
20. 25. 27. 30. 33. 35. 53. 57. 59. 61. 66. 72. 80. 92.
97. 99. 103. 108. 110. 112. 114. 116. 118. 122. 124. 126. 132. 138.
148. 150. 155. 157. 159. 161. 164. 186. 188. 194. 203. 211. 214. 216.
218. 8. 10. 22. 32. 39. 41. 43. 45. 49. 54. 67. 69. 74.
76. 81. 96. 105. 107. 119. 137. 142. 144. 146. 151. 153. 168. 170.
173. 175. 183. 185. 190. 195. 197. 209. 212. 19. 51. 56. 78. 83.
85. 88. 90. 94. 109. 131. 134. 136. 192. 199. 201. 205. 210. 215.
48. 71. 79. 123. 127. 129. 141. 166. 176. 178. 180. 182. 207. 213.
28. 139. 163. 171. 221. 6. 26. 46. 60. 100. 121. 220. 222. 224.
229. 231. 233. 235. 240. 31. 38. 187. 12. 23. 62. 64. 87. 217.
219. 227. 236. 238. 102. 149. 36. 223. 226. 228. 230. 225. 52. 242.
244. 246. 232. 234. 237. 239. 241. 251. 253.]
==================================================

Unique value counts for column 'Failure Type':


Failure Type
0 9653
1 112
3 95
4 78
2 45
5 17
Name: count, dtype: int64

Unique values for column 'Failure Type':


[0 3 2 4 5 1]
==================================================

In [5]: df = df.drop(["UDI","Product ID","Type"],axis=1)


print(df.shape)

localhost:8888/doc/tree/Innovative Assignment.ipynb 7/11


4/17/24, 10:31 PM Innovative Assignment

(10000, 6)

HANDLING MISSING VALUES

In [6]: mean1=np.mean(df.loc[~df.loc[:,"Torque [Nm]"].isna(),"Torque [Nm]"].values)


mean1=np.round(mean1)
df.loc[df.loc[:,"Torque [Nm]"].isna(),"Torque [Nm]"]=mean1
mean2=np.mean(df.loc[~df.loc[:,"Tool wear [min]"].isna(),"Tool wear [min]"].valu
mean2=np.round(mean2)
df.loc[df.loc[:,"Tool wear [min]"].isna(),"Tool wear [min]"]=mean2
df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10000 entries, 0 to 9999
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Air temperature [K] 10000 non-null float64
1 Process temperature [K] 10000 non-null float64
2 Rotational speed [rpm] 10000 non-null int64
3 Torque [Nm] 10000 non-null float64
4 Tool wear [min] 10000 non-null float64
5 Failure Type 10000 non-null int64
dtypes: float64(4), int64(2)
memory usage: 468.9 KB

STATISTICAL ANALYSIS OF DATA

In [7]: print(df.describe())
mean_values = df.mean()
median_values = df.median()
std_dev = df.std()
min_values = df.min()
max_values = df.max()
print()
print("MEAN")
print(mean_values)
print()
print("MEDIAN")
print(median_values)
print()
print("STANDARD DEVIATION")
print(std_dev)
print()
print("MINIMUM VALUES")
print(min_values)
print()
print("MAXIMUM VALUES")
print(max_values)

localhost:8888/doc/tree/Innovative Assignment.ipynb 8/11


4/17/24, 10:31 PM Innovative Assignment

Air temperature [K] Process temperature [K] Rotational speed [rpm] \


count 10000.000000 10000.000000 10000.000000
mean 300.004930 310.005560 1538.776100
std 2.000259 1.483734 179.284096
min 295.300000 305.700000 1168.000000
25% 298.300000 308.800000 1423.000000
50% 300.100000 310.100000 1503.000000
75% 301.500000 311.100000 1612.000000
max 304.500000 313.800000 2886.000000

Torque [Nm] Tool wear [min] Failure Type


count 10000.000000 10000.000000 10000.000000
mean 39.987960 107.947900 0.088400
std 9.965881 63.640044 0.523653
min 3.800000 0.000000 0.000000
25% 33.200000 53.000000 0.000000
50% 40.100000 108.000000 0.000000
75% 46.725000 162.000000 0.000000
max 76.600000 253.000000 5.000000

MEAN
Air temperature [K] 300.00493
Process temperature [K] 310.00556
Rotational speed [rpm] 1538.77610
Torque [Nm] 39.98796
Tool wear [min] 107.94790
Failure Type 0.08840
dtype: float64

MEDIAN
Air temperature [K] 300.1
Process temperature [K] 310.1
Rotational speed [rpm] 1503.0
Torque [Nm] 40.1
Tool wear [min] 108.0
Failure Type 0.0
dtype: float64

STANDARD DEVIATION
Air temperature [K] 2.000259
Process temperature [K] 1.483734
Rotational speed [rpm] 179.284096
Torque [Nm] 9.965881
Tool wear [min] 63.640044
Failure Type 0.523653
dtype: float64

MINIMUM VALUES
Air temperature [K] 295.3
Process temperature [K] 305.7
Rotational speed [rpm] 1168.0
Torque [Nm] 3.8
Tool wear [min] 0.0
Failure Type 0.0
dtype: float64

MAXIMUM VALUES
Air temperature [K] 304.5
Process temperature [K] 313.8
Rotational speed [rpm] 2886.0

localhost:8888/doc/tree/Innovative Assignment.ipynb 9/11


4/17/24, 10:31 PM Innovative Assignment

Torque [Nm] 76.6


Tool wear [min] 253.0
Failure Type 5.0
dtype: float64

APPLICABLE PLOTS TO VISUALIZE DATA

In [8]: import seaborn as sns


import matplotlib.pyplot as plt
fig, vg = plt.subplots(nrows=2, ncols=2, figsize=(14, 8))

sns.scatterplot(data=df, x="Torque [Nm]", y="Rotational speed [rpm]", hue="Failu


vg[0, 0].set_title('Scatter Plot')
vg[0, 0].set_xlabel('Torque [Nm]')
vg[0, 0].set_ylabel('Rotational speed [rpm]')

sns.lineplot(data=df, x="Air temperature [K]", y="Process temperature [K]", ax=v


vg[0, 1].set_title('Line Chart')
vg[0, 1].set_xlabel('Air Temperature [K]')
vg[0, 1].set_ylabel('Process Temperature [K]')

sns.histplot(data=df, x="Rotational speed [rpm]", bins=20, ax=vg[1, 0])


vg[1, 0].set_title('Histogram')
vg[1, 0].set_xlabel('Rotational speed')
vg[1, 0].set_ylabel('Frequency')

sns.boxplot(data=df, x="Failure Type", y="Tool wear [min]", ax=vg[1, 1])


vg[1, 1].set_title('Boxplot')
vg[1, 1].set_xlabel('Failure Type')
vg[1, 1].set_ylabel('Tool wear [min]')

plt.subplots_adjust(hspace=0.4)
plt.suptitle('Visualization Graphs')
plt.show

Out[8]: <function matplotlib.pyplot.show(close=None, block=None)>

localhost:8888/doc/tree/Innovative Assignment.ipynb 10/11


4/17/24, 10:31 PM Innovative Assignment

SPLITTING OF DATASET IN TRAINING SET AND TESTING SET

In [9]: X = df.iloc[:, :-1]


y = df.iloc[:, -1]
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size = 0.2,stratify

TRAINING AND TESTING DATA WITH K-NEAREST NEIGHBOR CLASSIFICATION MODEL

In [10]: k = int(input("Enter value of K:"))


model = KNeighborsClassifier(n_neighbors=k, weights = 'distance')
model.fit(X_train,y_train)
y_pred = model.predict(X_test)
accuracy = accuracy_score(y_test,y_pred)
print("ACCURACY:", accuracy*100)
print("\n")
print("CLASSIFICATION REPORT:\n\n" ,classification_report(y_test, y_pred))

ACCURACY: 96.15

CLASSIFICATION REPORT:

precision recall f1-score support

0 0.97 0.99 0.98 1931


1 0.17 0.05 0.07 22
2 0.00 0.00 0.00 9
3 0.38 0.16 0.22 19
4 0.40 0.25 0.31 16
5 0.00 0.00 0.00 3

accuracy 0.96 2000


macro avg 0.32 0.24 0.26 2000
weighted avg 0.95 0.96 0.95 2000

C:\Users\mazin\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn
\metrics\_classification.py:1509: UndefinedMetricWarning: Precision is ill-define
d and being set to 0.0 in labels with no predicted samples. Use `zero_division` p
arameter to control this behavior.
_warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
C:\Users\mazin\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn
\metrics\_classification.py:1509: UndefinedMetricWarning: Precision is ill-define
d and being set to 0.0 in labels with no predicted samples. Use `zero_division` p
arameter to control this behavior.
_warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))
C:\Users\mazin\AppData\Local\Programs\Python\Python312\Lib\site-packages\sklearn
\metrics\_classification.py:1509: UndefinedMetricWarning: Precision is ill-define
d and being set to 0.0 in labels with no predicted samples. Use `zero_division` p
arameter to control this behavior.
_warn_prf(average, modifier, f"{metric.capitalize()} is", len(result))

In [ ]:

localhost:8888/doc/tree/Innovative Assignment.ipynb 11/11

You might also like