Internet of Things (IoT) attacks and anomaly detection are becoming increasingly important. The rise of the Internet of Things infrastructure is accompanied by an increase in the number of assaults and threats directed against this infrastructure. Attacks like Denial of Service, Character Data Probing, Malicious Management, Malicious Activity, Inspection, Snooping, and Incorrect Setup might lead an IoT system to fail. To reliably detect attacks and abnormalities on IoT devices, many machine learning algorithms have been examined. Several machine learning (ML) techniques, including logistic regression, support vector machine, decision tree, random forest, and artificial neural network (ANN), are used in this scenario. A performance comparison is made using the measures of precision, clarity, accuracy, and F1 measure, but also an area under the Roc Curve. With Logistic Regression, Stochastic Tree, and ANN, the system achieved 93 percent test accuracy. Random Forest outperforms both strategies in terms of other criteria, despite the fact that they both have the same level of accuracy.