Summary Files Commits Branches @commit @diff @stats
path: root / Year 4 / Artificial Intelligence / hw05 / src / main.rs
diff options
context:
space:
mode:
Commitca4c08a327c2f173d93653b270767f9b6df8a969 (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-12-15 23:14:13 +0200
Committer
 Syndamia <kamen@syndamia.com>
2024-12-15 23:14:13 +0200
Filesdd811e02cd02406afc3fbac2b713d45bda846fa8 /Year 4/Artificial Intelligence/hw05/src/main.rs
uni-projects-ca4c08a327c2f173d93653b270767f9b6df8a969.tar
uni-projects-ca4c08a327c2f173d93653b270767f9b6df8a969.tar.gz
uni-projects-ca4c08a327c2f173d93653b270767f9b6df8a969.zip
Parent98f97cb8e6350aaa468ea812d99688376651092f (diff)
hw(AI/5): Add initial implementation
Not everything is done, no laplace, no logic on input 1, no folds
1 files changed, 40 insertions, 0 deletions
-rw-r--r--Year 4/Artificial Intelligence/hw05/src/main.rs40
diff --git a/Year 4/Artificial Intelligence/hw05/src/main.rs b/Year 4/Artificial Intelligence/hw05/src/main.rs
new file mode 100644
index 0000000..6a53ee8
--- /dev/null
+++ b/Year 4/Artificial Intelligence/hw05/src/main.rs
@@ -0,0 +1,40 @@
+use text_io::read;
+
+mod data;
+use data::{Person, Party::republican};
+mod probabilities;
+use probabilities::PMaps;
+
+fn test_single(prob: &PMaps, person: &Person) -> bool {
+ let is_republican = P!(Party = republican | person, prob) >= 0.5;
+ is_republican == (person.party == republican)
+}
+
+fn test(prob: &PMaps, people: &Vec<Person>) -> f64 {
+ let mut count_succ = 0.0;
+ for p in people {
+ if test_single(&prob, &p) {
+ count_succ += 1.0;
+ }
+ }
+ count_succ / people.len() as f64
+}
+
+fn main() {
+ let fill: u8 = read!();
+ let fill = fill == 1;
+
+ let (training, testing) = data::get_data();
+ let prob = if fill {
+ probabilities::value_2_probabilities(&training)
+ } else {
+ probabilities::value_3_probabilities(&training)
+ };
+
+ // No laplace, so that's probably why it's not 92.80%
+ println!("1. Train Set Accuracy:");
+ println!(" Accuracy: {:.2}%", test(&prob, &training) * 100.0);
+
+ println!("2. Test Set Accuracy:");
+ println!(" Accuracy: {:.2}%", test(&prob, &testing) * 100.0);
+}