コード例 #1
0
        internal Dictionary <string, int> GetPsychProfile(string[] documents)
        {
            string[]   d      = new string[] { documents.Aggregate((aggr, cur) => aggr + " " + cur) };
            double[][] inputs = TFIDF.Normalize(TFIDF.Transform(d));
            int[]      output = new int[9];

            Dictionary <string, int> result = new Dictionary <string, int>(9);

            output[0] = modelDenial.Decide(inputs[0]);
            output[1] = modelRepression.Decide(inputs[0]);
            output[2] = modelRegression.Decide(inputs[0]);
            output[3] = modelCompensation.Decide(inputs[0]);
            output[4] = modelProjection.Decide(inputs[0]);
            output[5] = modelDisplacement.Decide(inputs[0]);
            output[6] = modelRationalization.Decide(inputs[0]);
            output[7] = modelReactionFormation.Decide(inputs[0]);

            output[8] = output[0] + output[1] + output[2] + output[3] + output[4] + output[5] + output[6] + output[7];
            output[8] = Convert.ToInt32(Math.Round((double)output[8] / 8));

            result.Add("Отрицание", output[0]);
            result.Add("Вытеснение", output[1]);
            result.Add("Регрессия", output[2]);
            result.Add("Компенсация", output[3]);
            result.Add("Проекция", output[4]);
            result.Add("Замещение", output[5]);
            result.Add("Рационализация", output[6]);
            result.Add("Гиперкомпенсация", output[7]);
            result.Add("Общий уровень", output[8]);

            return(result);
        }
コード例 #2
0
        public string TFIDF_score(string[] webcontent)
        {
            TFIDF idf = new TFIDF();

            double[][] inputs = idf.Transform(webcontent, 0);
            inputs = TFIDF.Normalize(inputs);

            string final = "";

            for (int index = 0; index < inputs.Length; index++)
            {
                final = final + webcontent[index] + "\n";

                foreach (double value in inputs[index])
                {
                    final = value + ",";
                }

                final = final + "\n\n";
            }
            return(final);
        }
コード例 #3
0
ファイル: K_mean.cs プロジェクト: bashkims/ML_4C
        /// <summary>
        /// Generate KMean Clustering from text file and save to file
        /// </summary>
        /// <param name="filePath"> path of CVS file that contains data</param>
        /// <param name="columnname">Name of Column that has text to be considerd</param>
        /// <param name="ct">Column type</param>
        /// <param name="k">Number of clusters</param>
        /// <param name="maxiter">Maximun number of iterations</param>
        /// <param name="outputfile">Path where to save clustered data.</param>
        public void doIt(string filePath, string columnname, List <Type> ct, int k, int maxiter, string outputfile)
        {
            Common c = new Common();

            string[,] dt = c.getStringMatrix(filePath, ',', ct);
            string[] inp = c.getStringVector(dt, columnname);

            List <string> vocab = new List <string>();

            double[][] inputs = TFIDF.Transform(inp, ref vocab);

            inputs = TFIDF.Normalize(inputs);


            double[][] tf_labels = Common.getArrayRange(inputs, 0, 1, dt.Length);


            double[][] tf_centroids = smart_centroid_initalization(inputs, k, 0);


            List <double>             heter  = new List <double>();
            Tuple <double[][], int[]> result = kmeans(tf_labels, k, tf_centroids, maxiter, ref heter);


            List <List <double[]> > lld = new List <List <double[]> >();

            List <List <string> > lll = new List <List <string> >();

            for (int i = 0; i < k; i++)
            {
                lld.Add(new List <double[]>());
                lll.Add(new List <string>());
            }

            for (int i = 0; i < result.Item2.Length; i++)
            {
                lld[result.Item2[i]].Add(tf_labels[i]);
            }

            string[] vocabul = new string[k];
            for (int i = 0; i < k; i++)
            {
                List <double> ccc = result.Item1[i].ToList();
                ccc.Sort();
                ccc.Reverse();

                for (int j = 0; j < k; j++)
                {
                    vocabul[i] += vocab[Array.IndexOf(result.Item1[i], ccc[j])] + ": " + result.Item1[i][Array.IndexOf(result.Item1[i], ccc[j])] + "  ";
                }
            }

            using (TextWriter writer = File.CreateText(outputfile))
            {
                for (int i = 0; i < result.Item2.Length; i++)
                {
                    writer.WriteLine(inp[i] + "," + vocabul[result.Item2[i]]);
                    lll[result.Item2[i]].Add(inp[i]);
                }
            }

            Console.WriteLine("Finished!!!");
            Console.ReadKey();
        }