miniproject (1)
.py
keyboard_arrow_up
School
University of Massachusetts, Amherst *
*We aren’t endorsed by this school
Course
410
Subject
Electrical Engineering
Date
Jan 9, 2024
Type
py
Pages
5
Uploaded by ChefHeat7492
# -*- coding: utf-8 -*-
"""MiniProject.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1bj_Sy7v0VLzOD9X-ual0SHzhy5ehBbL8
<h1 align="center"><strong>DS/CMPSC 410 - Mini Project</strong></h1>
<h2 align="center"><strong>Crime Analysis in Chicago City.</strong></h2>
## Instructor: Professor Romit Maulik
## Team Members:
### - Sai Sanwariya Narayan
### - Nikhil Melligeri
### - Shafwat Mustafa
### - Rohan Singh
### - Shengdi You
### - Daniel Gao
### - Nathan Quint
"""
##pip install pyspark
import pyspark
import pandas as pd
import numpy as np
from pyspark import SparkContext
from pyspark.sql import SparkSession
from pyspark.sql.types import StructField, StructType, StringType, LongType, IntegerType, FloatType
from pyspark.sql.functions import col, column
from pyspark.sql.functions import expr
from pyspark.sql.functions import split
from datetime import datetime
import matplotlib.pyplot as plt
from pyspark.sql import Row
crime=SparkSession.builder.master("local").appName("CrimeDataAnalysis").getOrCreate
()
crime.sparkContext.setCheckpointDir("~/scratch")
"""## Uploading 2022 Crime Data"""
Data22 = crime.read.csv("/storage/home/njq5013/Project/Crimes_-_2022_20231016.csv",
header=True, inferSchema=True)
Data22.printSchema()
DF_2 = Data22.select("Primary Type" , "Location Description")
DF_2.take(10)
"""## Cleaning 2022 Crime Data"""
cleandata22 = DF_2.filter(DF_2["Primary Type"].isNotNull())
cleandata22.show(10)
"""## Uploading 2023 Crime Data"""
Data23 = crime.read.csv("/storage/home/njq5013/Project/Crimes_-_2023_20231016.csv",
inferSchema = True, header = True)
Data22.printSchema()
DF_3 = Data23.select("Primary Type" , "Location Description")
DF_3.take(10)
"""## Cleaning 2022 Crime Data"""
cleandata23 = DF_3.filter(DF_3["Primary Type"].isNotNull())
cleandata23.show(10)
"""## Data Merging with 2022 - 2023"""
Data22_23 = Data22.union(Data23)
print(Data22.count())
print(Data23.count())
print(Data22.count() + Data23.count())
print(Data22_23.count())
Data22_23.printSchema()
"""## Selecting useful columns"""
df = Data22_23.select("Date", "Block", "Primary Type", "Description", "Location Description", "Arrest", "Domestic",
"Beat", "District", "Ward", "Community Area", "Year")
"""## Removing rows with null values"""
df_clean = df.dropna(how = 'any')
print(df.count())
print(df_clean.count())
"""## INITIAL EDA AND MAPREDUCE"""
mapped_primary_type = df_clean.rdd.map(lambda row: (row["Primary Type"], 1))
reduced_primary_type = mapped_primary_type.reduceByKey(lambda a, b: a + b)
sorted_primary_type = reduced_primary_type.sortBy(lambda x: x[1], ascending=False)
primary_type_counts_sorted = sorted_primary_type.collect()
primary = [] #empty list for visualization
counts = [] #empty list for visualization
for primary_type, count in primary_type_counts_sorted:
print(f"Primary Type: {primary_type} -> Count: {count}")
primary.append(primary_type) #the first column (primary type)
counts.append(int(count)) #the second column (counts)
"""## Visualization - Primary type and count"""
#bar plot of primary_type and counts
plt.bar(primary, counts) #from above
plt.xlabel('Primary Type')
plt.ylabel('Count')
plt.title('Primary Type Counts')
plt.xticks(rotation = 90)#readability is bad without this, unless we switch the axis
plt.show()
#line plot - same thing as top
plt.plot(primary, counts, marker = "o") #from above
plt.xlabel('Primary Type')
plt.ylabel('Count')
plt.title('Primary Type Counts')
plt.xticks(rotation = 90)#readability is bad without this, unless we switch the axis
plt.show()
# MapReduce to count occurrences based on multiple attributes
# Map function to extract the required attributes and create key-value pairs
def map_attributes(row):
date_obj = datetime.strptime(row["Date"], "%m/%d/%Y %I:%M:%S %p") # Adjust date format if necessary
month = date_obj.month
year = row["Year"]
key = (row["Primary Type"], row["Location Description"], month, year, row["Block"], row["Ward"], row["District"])
return (key, 1)
# Map phase
mapped_data = df_clean.rdd.map(map_attributes)
# Reduce phase: Sum the values for each key
reduced_data = mapped_data.reduceByKey(lambda a, b: a + b)
# Sort the results in descending order based on count
sorted_data = reduced_data.sortBy(lambda x: x[1], ascending=False)
# Collect the sorted results
aggregated_counts_sorted = sorted_data.collect()
# Displaying the first few sorted results for verification
for (primary_type, location_description, month, year, block, ward, district), count
in aggregated_counts_sorted[:10]:
print(f"Primary Type: {primary_type}, Location: {location_description}, Month: {month}, Year: {year}, Block: {block}, Ward: {ward}, District: {district} -> Count:
{count}")
# MapReduce to count occurrences for each type of crime in each ward
mapped_rdd = df_clean.rdd.map(lambda row: ((row["Ward"], row["Primary Type"]), 1))
reduced_rdd = mapped_rdd.reduceByKey(lambda a, b: a + b)
ward_crime_counts = reduced_rdd.collect()
# Selecting a specific ward for visualization (e.g., Ward 10)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
For the cct shown below find zt
and drow the equivalent cct
IPD
I
Cgdp
RE
Cgdn
CPD
VDD
Mp
Ma
HH
Figure 5. Schematic diagram of the Inv-TIA.
Cout
arrow_forward
can someone explain how to do this problem step by step
arrow_forward
Identify the incorrect
sentence from the following.
O a. FET is a passive
component.
O b. BJT is a active
component.
C. active components
amplify the signals
applied to it.
d. Passive components
do not amplify the
signals applied to it.
arrow_forward
Question6
Plz provide answer
arrow_forward
The required 7-segmrnt decoder should have 3-inputs (which are the bits of the binary number desired to
be designed, call them A,B,C), and 7 outputs (the 7 segments of the display unit which are a, b, c, d, e, f
& g).
8.
gf a b
t la Ob
d Dp
e d8c Dp
The 7-segment to be used is of common anode type. Consequently, any segment will be ON if its input
is Low, meaning that for displaying 0 the segments inputs (a,b,c,d,e,f.g) should be (0000001), or g will be
OFF while all the others are ON.
1- Make a table explaining the inputs and the corresponding outputs for the 6 combinations input
(000.101), assuming the other two combinations as don't care.
2-
Find the output as a function of the inputs (A,B,C) using K-map to minimize the expressions
3-
Show your design using 2-input, and 3-input NAND gates, and inverter.
arrow_forward
We want to design a digital circuit that converts
Gray code (ABC) to Binary code (xyz). Set up a 8-to-
1 line multiplexer so that the output gives y as a
function of ABC. "A" is given to the most significant
bit of the control inputs of the multiplexer. "C" is
given to the least significant bit of the control inputs
of the multiplexer.
arrow_forward
Draw the graphs of the Manchester, differential Manchester, NRZ-I and NRZ-L schemes for each of the following data streams:
00110011
10101010
arrow_forward
Design a combinational circuit that takes 3-bit pattern as input and outputs binary code of bit
position of the first 1' in the pattern reading from MSB (2nd position) to LSB (0th position).An
additional output variable V is required along with binary code to indicate that the binary code
is valid or note i.e., if the input pattern is '000' then the output V should be '0' to indicate that
the binary code is not indicating the bit position of first 1' and we don't care about the binary
code if V = 0.
Design the required circuit using dual 4x1 MUXS and minimum additional logic.Available
resources along with dual 4x1 MUXS are NOT gates, 2-input(AND, OR, NAND, NOR)
gates.
arrow_forward
Consider the following runtime stack:
BEFORE
00001000
00000006
ESP
00000FFC
00000FF 8
00000FF 4
00000FF0
What would be the value of ESP after pushing the 32-bit value shown below onto the stack?
000000A5
O 00001020
O 00000FF8
O 00000FFC
O 000000A5
arrow_forward
B/Select the correct answer:
1) The basic structures in VHDL contain
a) Entity
b)
Architecture
The com
IVIUE
NJIHOVIO.
c) Library
d) All of them
nea
3) VHDL is a
design language.
a) Software b) Hardware c) Software and Hardware d) Not all is mentioned
arrow_forward
23. Determine the step size for a 4-bit ADC having a range of 10V. Also, convert an analog sample of 3V into the 4-bit digits using Successive approximation method. Please show all steps/comparisons/SAR comparison rules used for each step to obtain full points.
arrow_forward
Consider Analog to Digital Converters, calculate the following for a 3-bit quantizer with a range
from -5 to 5 V.
a) How many levels does this ADC have?
b) Determine the quantization step size
c) Determine the quantization error
d) In case the accuracy required imposes a quantization error less than 4 mV, what is
the specification needed for the used ADC?
arrow_forward
Stringing of cells in a PV panel
Draw the tabbing and bus-bar wires for a
72 cell module using three substrings and
a junction box mounted in
the typical central location. Each
substring is protected by a bypass diode.
No precision drawing is needed (i.e. you
don't need to draw every single cell,
the main arrangement of substring and
how you connect to the jnction-box is
relevant.
arrow_forward
2-bit by 2-bit binary multiplier using ROM VHDL code
arrow_forward
Draw the V-I characteristics of SCR,MOSFET,IGBT,DIAC and TRIAC
arrow_forward
De fine time constant (I) for (R-L) cct.
arrow_forward
Explain by block diagram and equations the PLL method of Demodulating FM
arrow_forward
PROTON development department wants to design an embedded safety warningsystem that able to monitor child seat belt condition in their upcoming vehicle launch.There are THREE independent sensors input labeled as X, Y and Z to produce THREEoutputs signal of R, S and T. Sensor X was embedded at bottom seat and sensor Y wasassigned at headrest support. While sensor Z was assign at buckle clip. All sensorproduces HIGH when pressed or tug in.Output R will be HIGH when both input X and Y is HIGH.Output S will be HIGH when input Z and output R is HIGH.Output T will be HIGH when output R is LOW but output Z is HIGH
arrow_forward
PROTON development department wants to design an embedded safety warningsystem that able to monitor child seat belt condition in their upcoming vehicle launch.There are THREE independent sensors input labeled as X, Y and Z to produce THREEoutputs signal of R, S and T. Sensor X was embedded at bottom seat and sensor Y wasassigned at headrest support. While sensor Z was assign at buckle clip. All sensorproduces HIGH when pressed or tug in.Output R will be HIGH when both input X and Y is HIGH.Output S will be HIGH when input Z and output R is HIGH.Output T will be HIGH when output R is LOW but output Z is HIGH.
arrow_forward
PROTON development department wants to design an embedded safety warningsystem that able to monitor child seat belt condition in their upcoming vehicle launch.There are THREE independent sensors input labeled as X, Y and Z to produce THREEoutputs signal of R, S and T. Sensor X was embedded at bottom seat and sensor Y wasassigned at headrest support. While sensor Z was assign at buckle clip. All sensorproduces HIGH when pressed or tug in.Output R will be HIGH when both input X and Y is HIGH.Output S will be HIGH when input Z and output R is HIGH.Output T will be HIGH when output R is LOW but output Z is HIGH
arrow_forward
Jdhsjdfzs
arrow_forward
10
arrow_forward
DON'T NEED TO WRITE STORIES.DON'T COPY. OTHERWISE I WILL GIVE YOU DOWNVOTE.
42) What is the function of MCB. Write two advantages and disadvantages of MCB.
arrow_forward
Answer the D, E and F part
arrow_forward
A static VAR compensator consists of:
A. TCRs in parallel with one or more TSCs
B. Only TCR's
C. Only TSC's
D. TCRs in series with one or more TSCs
arrow_forward
1. Determine the number of terminal phase states in the state trellis diagram for (a) a full response binary CPFSK with either h = 2/3 or 3/4 and (b) a partial response L = 3 binary CPFSK with either h = 2/3 or 3/4 .
arrow_forward
What is a JFET? Explain its construction and describe the biasing methods available for biasing a JFET?
Please don't write on paper
arrow_forward
Question 2
Incorrect
Mark 0.00 out of 1.00
P Flag question
In a self-bias n-channel JFET, the operating
point is to be set at Ip = 1.5 mA and Vps =10
V. The JFET parameters are IDss= 5 mA and
Vp = 2 V.
Given that VDD = 20 V.
The value of Rs required for the circuit is
Select one:
a. 60.3 kohms
b. 603 ohms
c. 60.3 ohms
d. 603 kohms
Your answer is incorrect.
The correct answer is: 603 ohms
arrow_forward
The waveforms in figure 1 below are observed on the inputs of a 74LS151 8-
input multiplexer shown in figure 2. Remember that when the enable is not
active the output is LOW.
2.1.1 Sketch the truth table for the Y output
2.1..2 Sketch the Y output waveform.
arrow_forward
draw the curcuit diagram for 4 channel 4 bit multiplexer implemented using 4 channel 1 bit multiplexer.
make sure that i need full circuit to save the final multiplexer in the library.
arrow_forward
Please can you design and draw the solution to this question.
arrow_forward
orescribed action accordingly.
A) Regulating trade, B) monitoring functions. C) measure physical quantities,
D) standard units.
2)A--------- a an output that varies in discrete steps and so can only have a finite
number of values.
A) Analogue instruments, B) digital instrument, C) Null-type ,D) passive instrument.
) a good measurement technician can substantially reduce errors at the output of a
measurement system by---------?
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Introductory Circuit Analysis (13th Edition)
Electrical Engineering
ISBN:9780133923605
Author:Robert L. Boylestad
Publisher:PEARSON
Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:9781337900348
Author:Stephen L. Herman
Publisher:Cengage Learning
Programmable Logic Controllers
Electrical Engineering
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Fundamentals of Electric Circuits
Electrical Engineering
ISBN:9780078028229
Author:Charles K Alexander, Matthew Sadiku
Publisher:McGraw-Hill Education
Electric Circuits. (11th Edition)
Electrical Engineering
ISBN:9780134746968
Author:James W. Nilsson, Susan Riedel
Publisher:PEARSON
Engineering Electromagnetics
Electrical Engineering
ISBN:9780078028151
Author:Hayt, William H. (william Hart), Jr, BUCK, John A.
Publisher:Mcgraw-hill Education,
Related Questions
- For the cct shown below find zt and drow the equivalent cct IPD I Cgdp RE Cgdn CPD VDD Mp Ma HH Figure 5. Schematic diagram of the Inv-TIA. Coutarrow_forwardcan someone explain how to do this problem step by steparrow_forwardIdentify the incorrect sentence from the following. O a. FET is a passive component. O b. BJT is a active component. C. active components amplify the signals applied to it. d. Passive components do not amplify the signals applied to it.arrow_forward
- Question6 Plz provide answerarrow_forwardThe required 7-segmrnt decoder should have 3-inputs (which are the bits of the binary number desired to be designed, call them A,B,C), and 7 outputs (the 7 segments of the display unit which are a, b, c, d, e, f & g). 8. gf a b t la Ob d Dp e d8c Dp The 7-segment to be used is of common anode type. Consequently, any segment will be ON if its input is Low, meaning that for displaying 0 the segments inputs (a,b,c,d,e,f.g) should be (0000001), or g will be OFF while all the others are ON. 1- Make a table explaining the inputs and the corresponding outputs for the 6 combinations input (000.101), assuming the other two combinations as don't care. 2- Find the output as a function of the inputs (A,B,C) using K-map to minimize the expressions 3- Show your design using 2-input, and 3-input NAND gates, and inverter.arrow_forwardWe want to design a digital circuit that converts Gray code (ABC) to Binary code (xyz). Set up a 8-to- 1 line multiplexer so that the output gives y as a function of ABC. "A" is given to the most significant bit of the control inputs of the multiplexer. "C" is given to the least significant bit of the control inputs of the multiplexer.arrow_forward
- Draw the graphs of the Manchester, differential Manchester, NRZ-I and NRZ-L schemes for each of the following data streams: 00110011 10101010arrow_forwardDesign a combinational circuit that takes 3-bit pattern as input and outputs binary code of bit position of the first 1' in the pattern reading from MSB (2nd position) to LSB (0th position).An additional output variable V is required along with binary code to indicate that the binary code is valid or note i.e., if the input pattern is '000' then the output V should be '0' to indicate that the binary code is not indicating the bit position of first 1' and we don't care about the binary code if V = 0. Design the required circuit using dual 4x1 MUXS and minimum additional logic.Available resources along with dual 4x1 MUXS are NOT gates, 2-input(AND, OR, NAND, NOR) gates.arrow_forwardConsider the following runtime stack: BEFORE 00001000 00000006 ESP 00000FFC 00000FF 8 00000FF 4 00000FF0 What would be the value of ESP after pushing the 32-bit value shown below onto the stack? 000000A5 O 00001020 O 00000FF8 O 00000FFC O 000000A5arrow_forward
- B/Select the correct answer: 1) The basic structures in VHDL contain a) Entity b) Architecture The com IVIUE NJIHOVIO. c) Library d) All of them nea 3) VHDL is a design language. a) Software b) Hardware c) Software and Hardware d) Not all is mentionedarrow_forward23. Determine the step size for a 4-bit ADC having a range of 10V. Also, convert an analog sample of 3V into the 4-bit digits using Successive approximation method. Please show all steps/comparisons/SAR comparison rules used for each step to obtain full points.arrow_forwardConsider Analog to Digital Converters, calculate the following for a 3-bit quantizer with a range from -5 to 5 V. a) How many levels does this ADC have? b) Determine the quantization step size c) Determine the quantization error d) In case the accuracy required imposes a quantization error less than 4 mV, what is the specification needed for the used ADC?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Introductory Circuit Analysis (13th Edition)Electrical EngineeringISBN:9780133923605Author:Robert L. BoylestadPublisher:PEARSONDelmar's Standard Textbook Of ElectricityElectrical EngineeringISBN:9781337900348Author:Stephen L. HermanPublisher:Cengage LearningProgrammable Logic ControllersElectrical EngineeringISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
- Fundamentals of Electric CircuitsElectrical EngineeringISBN:9780078028229Author:Charles K Alexander, Matthew SadikuPublisher:McGraw-Hill EducationElectric Circuits. (11th Edition)Electrical EngineeringISBN:9780134746968Author:James W. Nilsson, Susan RiedelPublisher:PEARSONEngineering ElectromagneticsElectrical EngineeringISBN:9780078028151Author:Hayt, William H. (william Hart), Jr, BUCK, John A.Publisher:Mcgraw-hill Education,
Introductory Circuit Analysis (13th Edition)
Electrical Engineering
ISBN:9780133923605
Author:Robert L. Boylestad
Publisher:PEARSON
Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:9781337900348
Author:Stephen L. Herman
Publisher:Cengage Learning
Programmable Logic Controllers
Electrical Engineering
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Fundamentals of Electric Circuits
Electrical Engineering
ISBN:9780078028229
Author:Charles K Alexander, Matthew Sadiku
Publisher:McGraw-Hill Education
Electric Circuits. (11th Edition)
Electrical Engineering
ISBN:9780134746968
Author:James W. Nilsson, Susan Riedel
Publisher:PEARSON
Engineering Electromagnetics
Electrical Engineering
ISBN:9780078028151
Author:Hayt, William H. (william Hart), Jr, BUCK, John A.
Publisher:Mcgraw-hill Education,