Skip to content

Commit f9e5e9b

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 19ab832 + 36d4833 commit f9e5e9b

22 files changed

+23152
-36
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.userosscache
8+
*.sln.docstates
9+
10+
# User-specific files (MonoDevelop/Xamarin Studio)
11+
*.userprefs
12+
13+
# Build results
14+
[Dd]ebug/
15+
[Dd]ebugPublic/
16+
[Rr]elease/
17+
[Rr]eleases/
18+
x64/
19+
x86/
20+
build/
21+
bld/
22+
[Bb]in/
23+
[Oo]bj/
24+
25+
# Visual Studo 2015 cache/options directory
26+
.vs/
27+
28+
# MSTest test Results
29+
[Tt]est[Rr]esult*/
30+
[Bb]uild[Ll]og.*
31+
32+
# NUNIT
33+
*.VisualState.xml
34+
TestResult.xml
35+
36+
# Build Results of an ATL Project
37+
[Dd]ebugPS/
38+
[Rr]eleasePS/
39+
dlldata.c
40+
41+
# DNX
42+
project.lock.json
43+
artifacts/
44+
45+
*_i.c
46+
*_p.c
47+
*_i.h
48+
*.ilk
49+
*.meta
50+
*.obj
51+
*.pch
52+
*.pdb
53+
*.pgc
54+
*.pgd
55+
*.rsp
56+
*.sbr
57+
*.tlb
58+
*.tli
59+
*.tlh
60+
*.tmp
61+
*.tmp_proj
62+
*.log
63+
*.vspscc
64+
*.vssscc
65+
.builds
66+
*.pidb
67+
*.svclog
68+
*.scc
69+
70+
# Chutzpah Test files
71+
_Chutzpah*
72+
73+
# Visual C++ cache files
74+
ipch/
75+
*.aps
76+
*.ncb
77+
*.opensdf
78+
*.sdf
79+
*.cachefile
80+
81+
# Visual Studio profiler
82+
*.psess
83+
*.vsp
84+
*.vspx
85+
86+
# TFS 2012 Local Workspace
87+
$tf/
88+
89+
# Guidance Automation Toolkit
90+
*.gpState
91+
92+
# ReSharper is a .NET coding add-in
93+
_ReSharper*/
94+
*.[Rr]e[Ss]harper
95+
*.DotSettings.user
96+
97+
# JustCode is a .NET coding addin-in
98+
.JustCode
99+
100+
# TeamCity is a build add-in
101+
_TeamCity*
102+
103+
# DotCover is a Code Coverage Tool
104+
*.dotCover
105+
106+
# NCrunch
107+
_NCrunch_*
108+
.*crunch*.local.xml
109+
110+
# MightyMoose
111+
*.mm.*
112+
AutoTest.Net/
113+
114+
# Web workbench (sass)
115+
.sass-cache/
116+
117+
# Installshield output folder
118+
[Ee]xpress/
119+
120+
# DocProject is a documentation generator add-in
121+
DocProject/buildhelp/
122+
DocProject/Help/*.HxT
123+
DocProject/Help/*.HxC
124+
DocProject/Help/*.hhc
125+
DocProject/Help/*.hhk
126+
DocProject/Help/*.hhp
127+
DocProject/Help/Html2
128+
DocProject/Help/html
129+
130+
# Click-Once directory
131+
publish/
132+
133+
# Publish Web Output
134+
*.[Pp]ublish.xml
135+
*.azurePubxml
136+
# TODO: Comment the next line if you want to checkin your web deploy settings
137+
# but database connection strings (with potential passwords) will be unencrypted
138+
*.pubxml
139+
*.publishproj
140+
141+
# NuGet Packages
142+
*.nupkg
143+
# The packages folder can be ignored because of Package Restore
144+
**/packages/*
145+
# except build/, which is used as an MSBuild target.
146+
!**/packages/build/
147+
# Uncomment if necessary however generally it will be regenerated when needed
148+
#!**/packages/repositories.config
149+
150+
# Windows Azure Build Output
151+
csx/
152+
*.build.csdef
153+
154+
# Windows Store app package directory
155+
AppPackages/
156+
157+
# Visual Studio cache files
158+
# files ending in .cache can be ignored
159+
*.[Cc]ache
160+
# but keep track of directories ending in .cache
161+
!*.[Cc]ache/
162+
163+
# Others
164+
ClientBin/
165+
[Ss]tyle[Cc]op.*
166+
~$*
167+
*~
168+
*.dbmdl
169+
*.dbproj.schemaview
170+
*.pfx
171+
*.publishsettings
172+
node_modules/
173+
bower_components/
174+
175+
# RIA/Silverlight projects
176+
Generated_Code/
177+
178+
# Backup & report files from converting an old project file
179+
# to a newer Visual Studio version. Backup files are not needed,
180+
# because we have git ;-)
181+
_UpgradeReport_Files/
182+
Backup*/
183+
UpgradeLog*.XML
184+
UpgradeLog*.htm
185+
186+
# SQL Server files
187+
*.mdf
188+
*.ldf
189+
190+
# Business Intelligence projects
191+
*.rdl.data
192+
*.bim.layout
193+
*.bim_*.settings
194+
195+
# Microsoft Fakes
196+
FakesAssemblies/
197+
198+
# Node.js Tools for Visual Studio
199+
.ntvs_analysis.dat
200+
201+
# Visual Studio 6 build log
202+
*.plg
203+
204+
# Visual Studio 6 workspace options file
205+
*.opt
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NaiveBayesClassifier", "NaiveBayesClassifier\NaiveBayesClassifier.csproj", "{E4E3BD3F-58DC-4D14-A21D-4F0AA056B6C5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E4E3BD3F-58DC-4D14-A21D-4F0AA056B6C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E4E3BD3F-58DC-4D14-A21D-4F0AA056B6C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E4E3BD3F-58DC-4D14-A21D-4F0AA056B6C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E4E3BD3F-58DC-4D14-A21D-4F0AA056B6C5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{E4E3BD3F-58DC-4D14-A21D-4F0AA056B6C5}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>NaiveBayesClassifier</RootNamespace>
11+
<AssemblyName>NaiveBayesClassifier</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="OxyPlot, Version=2015.1.708.0, Culture=neutral, PublicKeyToken=638079a8f0bd61e9, processorArchitecture=MSIL">
36+
<HintPath>..\packages\OxyPlot.Core.2015.1.708-alpha\lib\net45\OxyPlot.dll</HintPath>
37+
<Private>True</Private>
38+
</Reference>
39+
<Reference Include="System" />
40+
<Reference Include="System.Core" />
41+
<Reference Include="System.Xml.Linq" />
42+
<Reference Include="System.Data.DataSetExtensions" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Data" />
45+
<Reference Include="System.Net.Http" />
46+
<Reference Include="System.Xml" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="ProbabilityCalculator.cs" />
50+
<Compile Include="Program.cs" />
51+
<Compile Include="Properties\AssemblyInfo.cs" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<None Include="App.config" />
55+
<None Include="packages.config" />
56+
</ItemGroup>
57+
<ItemGroup>
58+
<Content Include="SMSSpamCollection.txt">
59+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
60+
</Content>
61+
</ItemGroup>
62+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
63+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
64+
Other similar extension points exist, see Microsoft.Common.targets.
65+
<Target Name="BeforeBuild">
66+
</Target>
67+
<Target Name="AfterBuild">
68+
</Target>
69+
-->
70+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace NaiveBayesClassifier
8+
{
9+
public class Message
10+
{
11+
public string Label { get; set; }
12+
public string Content { get; set; }
13+
public double Spamicity { get; set; }
14+
}
15+
16+
public static class ProbabilityCalculator
17+
{
18+
public static List<Message> Messages { get; set; }
19+
public static double ProbSpam { get; set; }
20+
public static double ProbHam { get; set; }
21+
public static int SpamMessageCount { get; set; }
22+
public static int HamMessageCount { get; set; }
23+
24+
public static void CalculateGlobalProbabilities()
25+
{
26+
ProbSpam = (double)Messages.Count(m => m.Label == "spam") / Messages.Count;
27+
ProbHam = (double)Messages.Count(m => m.Label == "ham") / Messages.Count;
28+
//SpamMessageCount =
29+
}
30+
31+
public static void CalculateSpamicityOfMessage(Message message)
32+
{
33+
var words = message.Content.Split(' ').ToList();
34+
var wordProbs = words.Select(GetSpamicityOfWord).ToList();
35+
36+
var eta = wordProbs.Sum(wordProb => Math.Log(1 - wordProb) - Math.Log(wordProb));
37+
38+
message.Spamicity = 1.0 / (1 + Math.Exp(eta));
39+
}
40+
41+
public static double GetSpamicityOfWord(string word)
42+
{
43+
var probWordSpam = (double) Messages.Where(m => m.Label == "spam").Count(m => m.Content.Contains(word)) / Messages.Count(m => m.Label == "spam");
44+
var probWordHam = (double) Messages.Where(m => m.Label == "ham").Count(m => m.Content.Contains(word)) / Messages.Count(m => m.Label == "ham");
45+
46+
return (probWordSpam * ProbSpam) / (probWordSpam * ProbSpam + probWordHam * ProbHam);
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)